+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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;
-
-import org.sonar.api.ExtensionPoint;
-import org.sonar.api.resources.Resource;
-
-/**
- * Filter resources to save. For example, ignore a resource if its path matches an exclusion pattern (defined on the project).
- * Filters are applied to files, directories and packages only.
- *
- * If the method start(), without parameters, exists, then it is executed at startup.
- *
- * @since 1.12
- * @deprecated since 4.2. Analysis is file-system oriented. See {@link org.sonar.api.batch.fs.InputFileFilter}
- */
-@Deprecated
-@ScannerSide
-@ExtensionPoint
-public interface ResourceFilter {
-
- /**
- * Return true if the resource must be ignored, else it's saved into database.
- */
- boolean isIgnored(Resource resource);
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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;
-
-import java.util.Collection;
-import javax.annotation.CheckForNull;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.sensor.SensorContext;
-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;
-
-/**
- * @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
- */
-@Deprecated
-public abstract class SonarIndex {
-
- /**
- * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
- * If the method resource.getParent() does not return null, then this parent will be indexed too.
- *
- * @return false if the resource is excluded
- * @since 2.6
- */
- public abstract boolean index(Resource resource);
-
- /**
- * Indexes a resource. This method does nothing if the resource is already indexed.
- *
- * @param resource the resource to index. Not nullable
- * @param parentReference a reference to the indexed parent. If null, the resource is indexed as a direct child of project.
- * @return false if the parent is not indexed or if the resource is excluded
- * @since 2.6
- */
- public abstract boolean index(Resource resource, Resource parentReference);
-
- /**
- * Returns true if the referenced resource is excluded. An excluded resource is not indexed.
- * @since 2.6
- */
- public abstract boolean isExcluded(Resource reference);
-
- /**
- * @since 2.6
- */
- public abstract boolean isIndexed(Resource reference, boolean acceptExcluded);
-
- /**
- * Search for an indexed resource.
- *
- * @param reference the resource reference
- * @return the indexed resource, null if it's not indexed
- * @since 1.10. Generic types since 2.6.
- */
- public abstract <R extends Resource> R getResource(R reference);
-
- /**
- * @since 2.6
- */
- public abstract Resource getParent(Resource reference);
-
- /**
- * @since 2.6
- */
-
- public abstract Collection<Resource> getChildren(Resource reference);
-
- /**
- * @return source code associated with a specified resource, <code>null</code> if not available
- * (for example if resource is not a file)
- * @since 2.9
- * @deprecated since 5.0 sources are no more stored in SQ as a single blob. Use {@link InputFile#file()} to read file content from disk.
- */
- @Deprecated
- @CheckForNull
- public abstract String getSource(Resource resource);
-
- public abstract Project getProject();
-
- public abstract Collection<Resource> getResources();
-
- /**
- * Indexes the resource.
- * @return the indexed resource, even if it's excluded
- * @deprecated since 2.6. Use methods index()
- */
- @Deprecated
- public abstract Resource addResource(Resource resource);
-
- @CheckForNull
- public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric);
-
- @CheckForNull
- public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
-
- /**
- * Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
- * indexed before. Next versions will deactivate this automatic indexation.
- */
- public abstract Measure addMeasure(Resource resource, Measure measure);
-
- /**
- * @deprecated since 5.2 No more design features. No op.
- */
- @Deprecated
- public abstract Dependency addDependency(Dependency dependency);
-}
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.resources.Resource;
/**
* <p>This interface is not intended to be implemented by clients.
@ScannerSide
public interface FileLinesContextFactory {
- /**
- * @deprecated since 4.4 use {@link #createFor(InputFile)}
- */
- @Deprecated
- FileLinesContext createFor(Resource resource);
-
/**
* @since 4.2
*/
*/
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);
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;
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;
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;
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) {
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;
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);
}
}
- @Override
public Project getProject() {
return currentProject;
}
}
@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);
return filter.filter(unfiltered);
}
- @Override
public Measure addMeasure(Resource resource, Measure measure) {
Bucket bucket = getBucket(resource);
if (bucket != null) {
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) {
/**
* 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);
return null;
}
- @Override
public List<Resource> getChildren(Resource resource) {
List<Resource> children = Lists.newLinkedList();
Bucket bucket = getBucket(resource);
return children;
}
- @Override
public Resource getParent(Resource resource) {
Bucket bucket = getBucket(resource);
if (bucket != null && bucket.getParent() != null) {
return null;
}
- @Override
public boolean index(Resource resource) {
Bucket bucket = doIndex(resource);
return bucket != null;
return doIndex(resource, resource.getParent());
}
- @Override
public boolean index(Resource resource, Resource parentReference) {
Bucket bucket = doIndex(resource, parentReference);
return bucket != null;
return bucket;
}
- @Override
public boolean isExcluded(@Nullable Resource reference) {
return false;
}
- @Override
public boolean isIndexed(@Nullable Resource reference, boolean acceptExcluded) {
return getBucket(reference) != null;
}
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;
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.
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;
*/
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;
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;
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;
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);