aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2016-06-14 17:28:44 +0200
committerJulien HENRY <henryju@yahoo.fr>2016-07-05 14:00:16 +0200
commit5fea53afecb02e5c2f48864c6ce33bfae03642ec (patch)
tree37abcbbdac0341d568a404c4d417b16e30d62d6d /sonar-scanner-engine/src
parent3da9ab4746aacecbd7fa0f7ae0ebd3cf6fe211d6 (diff)
downloadsonarqube-5fea53afecb02e5c2f48864c6ce33bfae03642ec.tar.gz
sonarqube-5fea53afecb02e5c2f48864c6ce33bfae03642ec.zip
SONAR-7727 Remove SonarIndex and ResourceFilter
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java24
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java18
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java14
6 files changed, 17 insertions, 57 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
index e15c94877c1..cdc83a47d13 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
@@ -19,48 +19,26 @@
*/
package org.sonar.batch;
-import com.google.common.base.Preconditions;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.FileLinesContext;
import org.sonar.api.measures.FileLinesContextFactory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.scan.measure.MeasureCache;
public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
- private final SonarIndex index;
private final SensorContext sensorContext;
private final MetricFinder metricFinder;
private final MeasureCache measureCache;
- private final BatchComponentCache scannerComponentCache;
- public DefaultFileLinesContextFactory(SonarIndex index, SensorContext sensorContext, MetricFinder metricFinder, BatchComponentCache scannerComponentCache,
- MeasureCache measureCache) {
- this.index = index;
+ public DefaultFileLinesContextFactory(SensorContext sensorContext, MetricFinder metricFinder, MeasureCache measureCache) {
this.sensorContext = sensorContext;
this.metricFinder = metricFinder;
- this.scannerComponentCache = scannerComponentCache;
this.measureCache = measureCache;
}
@Override
- public FileLinesContext createFor(Resource resource) {
- Preconditions.checkArgument(ResourceUtils.isFile(resource));
- // Reload resource in case it use deprecated key
- File file = (File) index.getResource(resource);
- if (file == null) {
- throw new IllegalArgumentException("Unable to find resource " + resource + " in index.");
- }
- return new DefaultFileLinesContext(sensorContext, (InputFile) scannerComponentCache.get(file).inputComponent(), metricFinder, measureCache);
- }
-
- @Override
public FileLinesContext createFor(InputFile inputFile) {
return new DefaultFileLinesContext(sensorContext, inputFile, metricFinder, measureCache);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
index 91a61dfa3d3..ccb928a598d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
@@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
@@ -44,6 +43,7 @@ import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.sensor.DefaultSensorContext;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
@@ -51,11 +51,11 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
private static final Logger LOG = LoggerFactory.getLogger(DeprecatedSensorContext.class);
- private final SonarIndex index;
+ private final DefaultIndex index;
private final Project project;
private final CoverageExclusions coverageFilter;
- public DeprecatedSensorContext(InputModule module, SonarIndex index, Project project, Settings settings, FileSystem fs, ActiveRules activeRules,
+ public DeprecatedSensorContext(InputModule module, DefaultIndex index, Project project, Settings settings, FileSystem fs, ActiveRules activeRules,
AnalysisMode analysisMode, CoverageExclusions coverageFilter, SensorStorage sensorStorage, SonarQubeVersion sqVersion) {
super(module, settings, fs, activeRules, analysisMode, sensorStorage, sqVersion);
this.index = index;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java
index ebc8465b0d3..c1966f569e0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java
@@ -22,20 +22,20 @@ package org.sonar.batch.deprecated.perspectives;
import com.google.common.collect.Maps;
import java.util.Map;
import javax.annotation.CheckForNull;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.component.Perspective;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.BatchComponentCache;
+import org.sonar.batch.index.DefaultIndex;
public class BatchPerspectives implements ResourcePerspectives {
private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap();
- private final SonarIndex resourceIndex;
+ private final DefaultIndex resourceIndex;
private final BatchComponentCache componentCache;
- public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex, BatchComponentCache componentCache) {
+ public BatchPerspectives(PerspectiveBuilder[] builders, DefaultIndex resourceIndex, BatchComponentCache componentCache) {
this.resourceIndex = resourceIndex;
this.componentCache = componentCache;
for (PerspectiveBuilder builder : builders) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 2c8f1de8ffb..d816ae0dd85 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -35,7 +35,6 @@ import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.design.Dependency;
@@ -54,7 +53,7 @@ import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.DefaultSensorStorage;
import org.sonar.core.component.ComponentKeys;
-public class DefaultIndex extends SonarIndex {
+public class DefaultIndex {
private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class);
@@ -109,7 +108,6 @@ public class DefaultIndex extends SonarIndex {
}
}
- @Override
public Project getProject() {
return currentProject;
}
@@ -138,13 +136,11 @@ public class DefaultIndex extends SonarIndex {
}
@CheckForNull
- @Override
public Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric) {
return getMeasures(resource, MeasuresFilters.metric(metric));
}
@CheckForNull
- @Override
public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
// Reload resource so that effective key is populated
Resource indexedResource = getResource(resource);
@@ -166,7 +162,6 @@ public class DefaultIndex extends SonarIndex {
return filter.filter(unfiltered);
}
- @Override
public Measure addMeasure(Resource resource, Measure measure) {
Bucket bucket = getBucket(resource);
if (bucket != null) {
@@ -175,17 +170,14 @@ public class DefaultIndex extends SonarIndex {
return measure;
}
- @Override
public Dependency addDependency(Dependency dependency) {
return dependency;
}
- @Override
public Set<Resource> getResources() {
return buckets.keySet();
}
- @Override
public String getSource(Resource reference) {
Resource resource = getResource(reference);
if (resource instanceof File) {
@@ -204,13 +196,11 @@ public class DefaultIndex extends SonarIndex {
/**
* Does nothing if the resource is already registered.
*/
- @Override
public Resource addResource(Resource resource) {
Bucket bucket = doIndex(resource);
return bucket != null ? bucket.getResource() : null;
}
- @Override
@CheckForNull
public <R extends Resource> R getResource(@Nullable R reference) {
Bucket bucket = getBucket(reference);
@@ -220,7 +210,6 @@ public class DefaultIndex extends SonarIndex {
return null;
}
- @Override
public List<Resource> getChildren(Resource resource) {
List<Resource> children = Lists.newLinkedList();
Bucket bucket = getBucket(resource);
@@ -232,7 +221,6 @@ public class DefaultIndex extends SonarIndex {
return children;
}
- @Override
public Resource getParent(Resource resource) {
Bucket bucket = getBucket(resource);
if (bucket != null && bucket.getParent() != null) {
@@ -241,7 +229,6 @@ public class DefaultIndex extends SonarIndex {
return null;
}
- @Override
public boolean index(Resource resource) {
Bucket bucket = doIndex(resource);
return bucket != null;
@@ -254,7 +241,6 @@ public class DefaultIndex extends SonarIndex {
return doIndex(resource, resource.getParent());
}
- @Override
public boolean index(Resource resource, Resource parentReference) {
Bucket bucket = doIndex(resource, parentReference);
return bucket != null;
@@ -296,12 +282,10 @@ public class DefaultIndex extends SonarIndex {
return bucket;
}
- @Override
public boolean isExcluded(@Nullable Resource reference) {
return false;
}
- @Override
public boolean isIndexed(@Nullable Resource reference, boolean acceptExcluded) {
return getBucket(reference) != null;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index 6c0d4893b19..05718cf2c03 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -20,7 +20,6 @@
package org.sonar.batch.scan.filesystem;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.resources.File;
@@ -29,6 +28,7 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.BatchComponent;
import org.sonar.batch.index.BatchComponentCache;
+import org.sonar.batch.index.DefaultIndex;
/**
* Index all files/directories of the module in SQ database and importing source code.
@@ -39,11 +39,11 @@ import org.sonar.batch.index.BatchComponentCache;
public class ComponentIndexer {
private final Languages languages;
- private final SonarIndex sonarIndex;
+ private final DefaultIndex sonarIndex;
private final Project module;
private final BatchComponentCache componentCache;
- public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache componentCache) {
+ public ComponentIndexer(Project module, Languages languages, DefaultIndex sonarIndex, BatchComponentCache componentCache) {
this.module = module;
this.languages = languages;
this.sonarIndex = sonarIndex;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
index 554f175695f..8f5459ec40a 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
@@ -19,21 +19,16 @@
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.batch.fs.InputFile.Status;
-
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-
import java.io.File;
import java.io.IOException;
-
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatcher;
-import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.resources.AbstractLanguage;
@@ -43,8 +38,11 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.index.BatchComponent;
import org.sonar.batch.index.BatchComponentCache;
+import org.sonar.batch.index.DefaultIndex;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
@@ -57,7 +55,7 @@ public class ComponentIndexerTest {
public TemporaryFolder temp = new TemporaryFolder();
private File baseDir;
private DefaultFileSystem fs;
- private SonarIndex sonarIndex;
+ private DefaultIndex sonarIndex;
private AbstractLanguage cobolLanguage;
private Project project;
private ModuleFileSystemInitializer initializer;
@@ -67,7 +65,7 @@ public class ComponentIndexerTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
fs = new DefaultFileSystem(baseDir.toPath());
- sonarIndex = mock(SonarIndex.class);
+ sonarIndex = mock(DefaultIndex.class);
project = new Project("myProject");
initializer = mock(ModuleFileSystemInitializer.class);
mode = mock(DefaultAnalysisMode.class);