diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-05-20 10:10:34 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-21 00:00:49 +0200 |
commit | 921963613e862a3749cda659f5a9f8d4813ca13c (patch) | |
tree | 092be658d2d2852770118eb5426f89e167eb9b55 /sonar-batch | |
parent | 6e9f4404b707c8cd5d9f77a593fcb1aaf6293351 (diff) | |
download | sonarqube-921963613e862a3749cda659f5a9f8d4813ca13c.tar.gz sonarqube-921963613e862a3749cda659f5a9f8d4813ca13c.zip |
SONAR-6278 Stop relying on graph to store tests
Diffstat (limited to 'sonar-batch')
66 files changed, 869 insertions, 399 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java index 4318e0fa8ad..70fb4d77b2a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/DbDuplicationsIndex.java @@ -26,7 +26,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import org.sonar.core.duplication.DuplicationUnitDto; import org.sonar.duplications.block.Block; @@ -51,10 +51,10 @@ public class DbDuplicationsIndex { private final String languageKey; private final DuplicationDao dao; private final DatabaseSession session; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; public DbDuplicationsIndex(Project currentProject, DuplicationDao dao, - String language, DatabaseSession session, ResourceCache resourceCache) { + String language, DatabaseSession session, BatchComponentCache resourceCache) { this.dao = dao; this.session = session; this.resourceCache = resourceCache; diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java index 9f8fe75c46b..6ee5c5edc7d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/IndexFactory.java @@ -29,7 +29,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrap.DefaultAnalysisMode; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import javax.annotation.Nullable; @@ -43,9 +43,9 @@ public class IndexFactory { private final DuplicationDao dao; private final DefaultAnalysisMode mode; private final DatabaseSession session; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public IndexFactory(DefaultAnalysisMode mode, Settings settings, @Nullable DuplicationDao dao, @Nullable DatabaseSession session, ResourceCache resourceCache) { + public IndexFactory(DefaultAnalysisMode mode, Settings settings, @Nullable DuplicationDao dao, @Nullable DatabaseSession session, BatchComponentCache resourceCache) { this.mode = mode; this.settings = settings; this.dao = dao; @@ -56,7 +56,7 @@ public class IndexFactory { /** * Used by new sensor mode */ - public IndexFactory(DefaultAnalysisMode mode, Settings settings, ResourceCache resourceCache) { + public IndexFactory(DefaultAnalysisMode mode, Settings settings, BatchComponentCache resourceCache) { this(mode, settings, null, null, resourceCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java index 445508ab0f5..47124c44c29 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java @@ -20,56 +20,43 @@ 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.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.PerspectiveNotFoundException; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Map; +import org.sonar.batch.index.BatchComponentCache; public class BatchPerspectives implements ResourcePerspectives { private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap(); private final SonarIndex resourceIndex; + private final BatchComponentCache componentCache; - public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex) { + public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex, BatchComponentCache componentCache) { this.resourceIndex = resourceIndex; + this.componentCache = componentCache; for (PerspectiveBuilder builder : builders) { - // TODO check duplications this.builders.put(builder.getPerspectiveClass(), builder); } } @Override @CheckForNull - public <P extends Perspective> P as(Class<P> perspectiveClass, Component component) { - if (component.key() == null) { - return null; - } - PerspectiveBuilder<P> builder = builderFor(perspectiveClass); - return builder.loadPerspective(perspectiveClass, component); - } - - @Override - @CheckForNull public <P extends Perspective> P as(Class<P> perspectiveClass, Resource resource) { Resource indexedResource = resource; if (resource.getEffectiveKey() == null) { indexedResource = resourceIndex.getResource(resource); } if (indexedResource != null) { - return as(perspectiveClass, new ResourceComponent(indexedResource)); + PerspectiveBuilder<P> builder = builderFor(perspectiveClass); + return builder.loadPerspective(perspectiveClass, componentCache.get(indexedResource)); } return null; } @@ -84,7 +71,8 @@ public class BatchPerspectives implements ResourcePerspectives { } else { throw new IllegalArgumentException("Unknow input path type: " + inputPath); } - return as(perspectiveClass, r); + PerspectiveBuilder<P> builder = builderFor(perspectiveClass); + return builder.loadPerspective(perspectiveClass, componentCache.get(inputPath)); } private <T extends Perspective> PerspectiveBuilder<T> builderFor(Class<T> clazz) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java new file mode 100644 index 00000000000..6a18b67210e --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java @@ -0,0 +1,42 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.deprecated.perspectives; + +import javax.annotation.CheckForNull; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.component.Perspective; +import org.sonar.batch.index.BatchComponent; + +@BatchSide +public abstract class PerspectiveBuilder<T extends Perspective> { + + private final Class<T> perspectiveClass; + + protected PerspectiveBuilder(Class<T> perspectiveClass) { + this.perspectiveClass = perspectiveClass; + } + + public Class<T> getPerspectiveClass() { + return perspectiveClass; + } + + @CheckForNull + public abstract T loadPerspective(Class<T> perspectiveClass, BatchComponent component); +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java new file mode 100644 index 00000000000..d75067a4358 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java @@ -0,0 +1,26 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.deprecated.perspectives; + +public class PerspectiveNotFoundException extends RuntimeException { + public PerspectiveNotFoundException(String message) { + super(message); + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java index af4eedd4bd9..38655cc298b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java @@ -31,16 +31,16 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; -public class BatchResource { +public class BatchComponent { private final int batchId; private final Resource r; private Snapshot s; - private final BatchResource parent; - private final Collection<BatchResource> children = new ArrayList<>(); + private final BatchComponent parent; + private final Collection<BatchComponent> children = new ArrayList<>(); private InputPath inputPath; - public BatchResource(int batchId, Resource r, @Nullable BatchResource parent) { + public BatchComponent(int batchId, Resource r, @Nullable BatchComponent parent) { this.batchId = batchId; this.r = r; this.parent = parent; @@ -61,7 +61,7 @@ public class BatchResource { return r; } - public BatchResource setSnapshot(Snapshot snapshot) { + public BatchComponent setSnapshot(Snapshot snapshot) { this.s = snapshot; return this; } @@ -79,11 +79,11 @@ public class BatchResource { } @CheckForNull - public BatchResource parent() { + public BatchComponent parent() { return parent; } - public Collection<BatchResource> children() { + public Collection<BatchComponent> children() { return children; } @@ -95,7 +95,7 @@ public class BatchResource { return Qualifiers.isDirectory(r); } - public BatchResource setInputPath(InputPath inputPath) { + public BatchComponent setInputPath(InputPath inputPath) { this.inputPath = inputPath; return this; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java index 156ff96305f..f030027e24f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java @@ -19,74 +19,60 @@ */ package org.sonar.batch.index; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Maps; +import java.util.Collection; +import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; +import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.core.component.ScanGraph; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Map; @BatchSide -public class ResourceCache { - // resource by component key - private final Map<String, BatchResource> resources = Maps.newLinkedHashMap(); - - private BatchResource root; - private final ScanGraph scanGraph; - - public ResourceCache(ScanGraph scanGraph) { - this.scanGraph = scanGraph; - } +public class BatchComponentCache { + // components by key + private final Map<String, BatchComponent> components = Maps.newLinkedHashMap(); - @VisibleForTesting - public ResourceCache() { - this.scanGraph = null; - } + private BatchComponent root; @CheckForNull - public BatchResource get(String componentKey) { - return resources.get(componentKey); + public BatchComponent get(String componentKey) { + return components.get(componentKey); } - public BatchResource get(Resource resource) { - return resources.get(resource.getEffectiveKey()); + public BatchComponent get(Resource resource) { + return components.get(resource.getEffectiveKey()); } - public BatchResource get(InputFile inputFile) { - return resources.get(((DefaultInputFile) inputFile).key()); + public BatchComponent get(InputPath inputPath) { + if (inputPath instanceof DefaultInputFile) { + return components.get(((DefaultInputFile) inputPath).key()); + } + return components.get(((DefaultInputDir) inputPath).key()); } - public BatchResource add(Resource resource, @Nullable Resource parentResource) { + public BatchComponent add(Resource resource, @Nullable Resource parentResource) { String componentKey = resource.getEffectiveKey(); Preconditions.checkState(!Strings.isNullOrEmpty(componentKey), "Missing resource effective key"); - BatchResource parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null; - BatchResource batchResource = new BatchResource(resources.size() + 1, resource, parent); + BatchComponent parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null; + BatchComponent batchResource = new BatchComponent(components.size() + 1, resource, parent); // Libraries can have the same effective key than a project so we can't cache by effectiveKey - resources.put(componentKey, batchResource); + components.put(componentKey, batchResource); if (parent == null) { root = batchResource; } - if (scanGraph != null && ResourceUtils.isPersistable(batchResource.resource())) { - scanGraph.addComponent(batchResource.resource()); - } return batchResource; } - public Collection<BatchResource> all() { - return resources.values(); + public Collection<BatchComponent> all() { + return components.values(); } - public BatchResource getRoot() { + public BatchComponent getRoot() { return root; } } 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 bed28c439a5..63dac585a2c 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 @@ -91,7 +91,7 @@ public class DefaultIndex extends SonarIndex { CoreMetrics.DUPLICATIONS_DATA_KEY ); - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MetricFinder metricFinder; private final MeasureCache measureCache; // caches @@ -100,7 +100,7 @@ public class DefaultIndex extends SonarIndex { private DefaultProjectTree projectTree; private ModuleIssues moduleIssues; - public DefaultIndex(ResourceCache resourceCache, DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) { + public DefaultIndex(BatchComponentCache resourceCache, DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) { this.resourceCache = resourceCache; this.projectTree = projectTree; this.metricFinder = metricFinder; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index cf31dfdcaf5..504286a67af 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -20,6 +20,8 @@ package org.sonar.batch.index; import com.google.common.annotations.VisibleForTesting; +import javax.annotation.Nullable; +import javax.persistence.NonUniqueResultException; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.database.DatabaseSession; @@ -34,10 +36,6 @@ import org.sonar.api.resources.Scopes; import org.sonar.api.security.ResourcePermissions; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.internal.Uuids; -import org.sonar.core.component.ScanGraph; - -import javax.annotation.Nullable; -import javax.persistence.NonUniqueResultException; import static org.sonar.api.utils.DateUtils.dateToLong; @@ -48,29 +46,27 @@ public class ResourcePersister implements ScanPersister { private final DatabaseSession session; private final ResourcePermissions permissions; - private final ResourceCache resourceCache; - private final ScanGraph scanGraph; + private final BatchComponentCache resourceCache; - public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, ResourceCache resourceCache, ScanGraph scanGraph) { + public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, BatchComponentCache resourceCache) { this.session = session; this.permissions = permissions; this.resourceCache = resourceCache; - this.scanGraph = scanGraph; } @Override public void persist() { - for (BatchResource resource : resourceCache.all()) { + for (BatchComponent resource : resourceCache.all()) { persist(resource); } } - private void persist(BatchResource batchResource) { + private void persist(BatchComponent batchResource) { if (batchResource.snapshot() != null) { // already persisted return; } - BatchResource parentBatchResource = batchResource.parent(); + BatchComponent parentBatchResource = batchResource.parent(); Snapshot s; if (parentBatchResource != null) { persist(parentBatchResource); @@ -80,12 +76,9 @@ public class ResourcePersister implements ScanPersister { s = persistProject((Project) batchResource.resource(), null); } batchResource.setSnapshot(s); - if (ResourceUtils.isPersistable(batchResource.resource())) { - scanGraph.completeComponent(batchResource.key(), batchResource.resource().getId(), s.getId()); - } } - private Project findModule(BatchResource batchResource) { + private Project findModule(BatchComponent batchResource) { if (batchResource.resource() instanceof Project) { return (Project) batchResource.resource(); } else { @@ -147,7 +140,7 @@ public class ResourcePersister implements ScanPersister { * Everything except project and library */ private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) { - BatchResource moduleResource = resourceCache.get(project); + BatchComponent moduleResource = resourceCache.get(project); Integer moduleId = moduleResource.resource().getId(); ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project); model.setRootId(moduleId); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java index 578bb2bb49e..89561865d63 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java @@ -20,15 +20,14 @@ package org.sonar.batch.issue; import com.google.common.collect.Lists; -import org.sonar.api.component.Component; +import java.util.List; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.Project; +import org.sonar.batch.index.BatchComponent; import org.sonar.core.issue.DefaultIssueBuilder; -import java.util.List; - /** * @since 3.6 */ @@ -36,10 +35,10 @@ public class DefaultIssuable implements Issuable { private final ModuleIssues moduleIssues; private final IssueCache cache; - private final Component component; + private final BatchComponent component; private final Project project; - DefaultIssuable(Component component, Project project, ModuleIssues moduleIssues, IssueCache cache) { + DefaultIssuable(BatchComponent component, Project project, ModuleIssues moduleIssues, IssueCache cache) { this.component = component; this.project = project; this.moduleIssues = moduleIssues; @@ -56,32 +55,26 @@ public class DefaultIssuable implements Issuable { return moduleIssues.initAndAddIssue((DefaultIssue) issue); } - @SuppressWarnings("unchecked") @Override public List<Issue> resolvedIssues() { List<Issue> result = Lists.newArrayList(); for (DefaultIssue issue : cache.byComponent(component.key())) { - if (issue.resolution()!=null) { + if (issue.resolution() != null) { result.add(issue); } } return result; } - @SuppressWarnings("unchecked") @Override public List<Issue> issues() { List<Issue> result = Lists.newArrayList(); for (DefaultIssue issue : cache.byComponent(component.key())) { - if (issue.resolution()==null) { + if (issue.resolution() == null) { result.add(issue); } } return result; } - @Override - public Component component() { - return component; - } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java index 51ec2b9fe7e..1fda7c27513 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java @@ -19,14 +19,10 @@ */ package org.sonar.batch.issue; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issuable; -import org.sonar.api.resources.Scopes; import org.sonar.batch.DefaultProjectTree; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; /** * Create the perspective {@link Issuable} on components. @@ -45,13 +41,8 @@ public class IssuableFactory extends PerspectiveBuilder<Issuable> { this.projectTree = projectTree; } - @CheckForNull @Override - public Issuable loadPerspective(Class<Issuable> perspectiveClass, Component component) { - boolean supported = true; - if (component instanceof ResourceComponent) { - supported = Scopes.isHigherThanOrEquals(((ResourceComponent) component).scope(), Scopes.FILE); - } - return supported ? new DefaultIssuable(component, projectTree.getRootProject(), moduleIssues, cache) : null; + public Issuable loadPerspective(Class<Issuable> perspectiveClass, BatchComponent component) { + return new DefaultIssuable(component, projectTree.getRootProject(), moduleIssues, cache); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java index dfba07392e6..a946c9f7dea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java @@ -34,8 +34,8 @@ import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.resources.Project; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -62,12 +62,12 @@ public class LocalIssueTracking { private final IssueChangeContext changeContext; private final ActiveRules activeRules; private final InputPathCache inputPathCache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ServerIssueRepository serverIssueRepository; private final ProjectRepositories projectRepositories; private final AnalysisMode analysisMode; - public LocalIssueTracking(ResourceCache resourceCache, IssueCache issueCache, IssueTracking tracking, + public LocalIssueTracking(BatchComponentCache resourceCache, IssueCache issueCache, IssueTracking tracking, ServerLineHashesLoader lastLineHashes, IssueWorkflow workflow, IssueUpdater updater, ActiveRules activeRules, InputPathCache inputPathCache, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, AnalysisMode analysisMode) { @@ -93,12 +93,12 @@ public class LocalIssueTracking { serverIssueRepository.load(); - for (BatchResource component : resourceCache.all()) { + for (BatchComponent component : resourceCache.all()) { trackIssues(component); } } - public void trackIssues(BatchResource component) { + public void trackIssues(BatchComponent component) { Collection<DefaultIssue> issues = Lists.newArrayList(); for (Issue issue : issueCache.byComponent(component.resource().getEffectiveKey())) { @@ -136,7 +136,7 @@ public class LocalIssueTracking { } @CheckForNull - private SourceHashHolder loadSourceHashes(BatchResource component) { + private SourceHashHolder loadSourceHashes(BatchComponent component) { SourceHashHolder sourceHashHolder = null; if (component.isFile()) { DefaultInputFile file = (DefaultInputFile) inputPathCache.getInputPath(component); @@ -148,7 +148,7 @@ public class LocalIssueTracking { return sourceHashHolder; } - private Collection<ServerIssue> loadServerIssues(BatchResource component) { + private Collection<ServerIssue> loadServerIssues(BatchComponent component) { Collection<ServerIssue> serverIssues = new ArrayList<>(); for (org.sonar.batch.protocol.input.BatchInput.ServerIssue previousIssue : serverIssueRepository.byComponent(component)) { serverIssues.add(new ServerIssueFromWs(previousIssue)); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java index 81de6745192..79bedb1c112 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java @@ -29,10 +29,10 @@ import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.Cache; import org.sonar.batch.index.Caches; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.input.BatchInput.ServerIssue; import org.sonar.batch.repository.ServerIssuesLoader; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -54,11 +54,11 @@ public class ServerIssueRepository { private Cache<ServerIssue> issuesCache; private final ServerIssuesLoader previousIssuesLoader; private final ProjectReactor reactor; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final AnalysisMode analysisMode; private final InputPathCache inputPathCache; - public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, ResourceCache resourceCache, + public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, BatchComponentCache resourceCache, AnalysisMode analysisMode, InputPathCache inputPathCache) { this.caches = caches; this.previousIssuesLoader = previousIssuesLoader; @@ -83,7 +83,7 @@ public class ServerIssueRepository { return null; } String componentKey = ComponentKeys.createEffectiveKey(issue.getModuleKey(), issue.hasPath() ? issue.getPath() : null); - BatchResource r = resourceCache.get(componentKey); + BatchComponent r = resourceCache.get(componentKey); if (r == null) { // Deleted resource issuesCache.put(0, issue.getKey(), issue); @@ -96,7 +96,7 @@ public class ServerIssueRepository { profiler.stopDebug(); } - public Iterable<ServerIssue> byComponent(BatchResource component) { + public Iterable<ServerIssue> byComponent(BatchComponent component) { if (analysisMode.isIncremental()) { if (!component.isFile()) { throw new UnsupportedOperationException("Incremental mode should only get issues on files"); diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 321d495f929..55502e9ba78 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -41,7 +41,7 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.measures.Measure; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.Cache.Entry; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Component; @@ -120,7 +120,7 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { } private void storeMeasures(ProjectScanContainer container) { - ResourceCache resourceCache = container.getComponentByType(ResourceCache.class); + BatchComponentCache resourceCache = container.getComponentByType(BatchComponentCache.class); for (Entry<Measure> measureEntry : container.getComponentByType(MeasureCache.class).entries()) { String componentKey = measureEntry.key()[0].toString(); InputPath path = resourceCache.get(componentKey).inputPath(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java index 56840eb88b4..6f46c012ce9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java @@ -30,8 +30,8 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.Settings; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import javax.annotation.Nullable; @@ -41,9 +41,9 @@ public class DefaultPostJobContext implements PostJobContext { private final Settings settings; private final AnalysisMode analysisMode; private final IssueCache cache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public DefaultPostJobContext(Settings settings, AnalysisMode analysisMode, IssueCache cache, ResourceCache resourceCache) { + public DefaultPostJobContext(Settings settings, AnalysisMode analysisMode, IssueCache cache, BatchComponentCache resourceCache) { this.settings = settings; this.analysisMode = analysisMode; this.cache = cache; @@ -105,7 +105,7 @@ public class DefaultPostJobContext implements PostJobContext { @Override public InputPath inputPath() { - BatchResource component = resourceCache.get(wrapped.componentKey()); + BatchComponent component = resourceCache.get(wrapped.componentKey()); return component != null ? component.inputPath() : null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java index 657dbaba303..54427072235 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java +++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java @@ -34,7 +34,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.qualitygate.db.QualityGateConditionDto; import org.sonar.core.timemachine.Periods; @@ -55,9 +55,9 @@ public class QualityGateVerifier implements Decorator { private Periods periods; private I18n i18n; private Durations durations; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; - public QualityGateVerifier(QualityGate qualityGate, ResourceCache resourceCache, Periods periods, I18n i18n, Durations durations) { + public QualityGateVerifier(QualityGate qualityGate, BatchComponentCache resourceCache, Periods periods, I18n i18n, Durations durations) { this.qualityGate = qualityGate; this.resourceCache = resourceCache; this.periods = periods; diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java index 217458bcdea..2398ec25434 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java @@ -27,8 +27,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.resources.Language; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.Constants.ComponentLinkType; import org.sonar.batch.protocol.output.*; @@ -43,11 +43,11 @@ import javax.annotation.CheckForNull; */ public class ComponentsPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ProjectReactor reactor; private final EventCache eventCache; - public ComponentsPublisher(ProjectReactor reactor, ResourceCache resourceCache, EventCache eventCache) { + public ComponentsPublisher(ProjectReactor reactor, BatchComponentCache resourceCache, EventCache eventCache) { this.reactor = reactor; this.resourceCache = resourceCache; this.eventCache = eventCache; @@ -55,11 +55,11 @@ public class ComponentsPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { - BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); + BatchComponent rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); recursiveWriteComponent(rootProject, writer); } - private void recursiveWriteComponent(BatchResource batchResource, BatchReportWriter writer) { + private void recursiveWriteComponent(BatchComponent batchResource, BatchReportWriter writer) { Resource r = batchResource.resource(); BatchReport.Component.Builder builder = BatchReport.Component.newBuilder(); @@ -98,7 +98,7 @@ public class ComponentsPublisher implements ReportPublisherStep { if (lang != null) { builder.setLanguage(lang); } - for (BatchResource child : batchResource.children()) { + for (BatchComponent child : batchResource.children()) { builder.addChildRef(child.batchId()); } writeLinks(r, builder); @@ -106,12 +106,12 @@ public class ComponentsPublisher implements ReportPublisherStep { writeEvents(batchResource, builder); writer.writeComponent(builder.build()); - for (BatchResource child : batchResource.children()) { + for (BatchComponent child : batchResource.children()) { recursiveWriteComponent(child, writer); } } - private void writeEvents(BatchResource batchResource, Builder builder) { + private void writeEvents(BatchComponent batchResource, Builder builder) { if (ResourceUtils.isProject(batchResource.resource())) { for (Event event : eventCache.getEvents(batchResource.batchId())) { builder.addEvent(event); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java index 617e4d1b943..27a64a9e21f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java @@ -26,8 +26,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport.Coverage; import org.sonar.batch.protocol.output.BatchReport.Coverage.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -38,17 +38,17 @@ import java.util.Map; public class CoveragePublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MeasureCache measureCache; - public CoveragePublisher(ResourceCache resourceCache, MeasureCache measureCache) { + public CoveragePublisher(BatchComponentCache resourceCache, MeasureCache measureCache) { this.resourceCache = resourceCache; this.measureCache = measureCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java index 9b0dde87911..b40521f355f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java @@ -24,8 +24,8 @@ import com.google.common.collect.Iterables; import org.sonar.api.batch.sensor.duplication.Duplication.Block; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.*; import org.sonar.batch.protocol.output.BatchReport.Duplicate; import org.sonar.batch.protocol.output.BatchReport.Duplication; @@ -33,17 +33,17 @@ import org.sonar.batch.protocol.output.BatchReport.Range; public class DuplicationsPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final DuplicationCache duplicationCache; - public DuplicationsPublisher(ResourceCache resourceCache, DuplicationCache duplicationCache) { + public DuplicationsPublisher(BatchComponentCache resourceCache, DuplicationCache duplicationCache) { this.resourceCache = resourceCache; this.duplicationCache = duplicationCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } @@ -77,7 +77,7 @@ public class DuplicationsPublisher implements ReportPublisherStep { blockBuilder.clear(); String componentKey = duplicate.resourceKey(); if (!currentComponentKey.equals(componentKey)) { - BatchResource sameProjectComponent = resourceCache.get(componentKey); + BatchComponent sameProjectComponent = resourceCache.get(componentKey); if (sameProjectComponent != null) { blockBuilder.setOtherFileRef(sameProjectComponent.batchId()); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java b/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java index c7fdc589677..7ffc48bfd7d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/EventCache.java @@ -21,7 +21,7 @@ package org.sonar.batch.report; import org.sonar.api.batch.BatchSide; import org.sonar.api.resources.Resource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.EventCategory; import org.sonar.batch.protocol.output.BatchReport.Event; @@ -37,9 +37,9 @@ import java.util.Map; public class EventCache { private final Map<Integer, List<Event>> eventsByComponentBatchId = new HashMap<>(); - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public EventCache(ResourceCache resourceCache) { + public EventCache(BatchComponentCache resourceCache) { this.resourceCache = resourceCache; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java index f2268cd20a9..e2c70d590db 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java @@ -26,8 +26,8 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.resources.Project; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; @@ -41,11 +41,11 @@ import java.util.Iterator; public class IssuesPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final IssueCache issueCache; private final ProjectReactor reactor; - public IssuesPublisher(ProjectReactor reactor, ResourceCache resourceCache, IssueCache issueCache) { + public IssuesPublisher(ProjectReactor reactor, BatchComponentCache resourceCache, IssueCache issueCache) { this.reactor = reactor; this.resourceCache = resourceCache; this.issueCache = issueCache; @@ -54,7 +54,7 @@ public class IssuesPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { Collection<Object> deletedComponentKeys = issueCache.componentKeys(); - for (BatchResource resource : resourceCache.all()) { + for (BatchComponent resource : resourceCache.all()) { String componentKey = resource.resource().getEffectiveKey(); Iterable<DefaultIssue> issues = issueCache.byComponent(componentKey); writer.writeComponentIssues(resource.batchId(), Iterables.transform(issues, new Function<DefaultIssue, BatchReport.Issue>() { @@ -74,7 +74,7 @@ public class IssuesPublisher implements ReportPublisherStep { } private void exportMetadata(BatchReportWriter writer, int count) { - BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); + BatchComponent rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); BatchReport.Metadata.Builder builder = BatchReport.Metadata.newBuilder() .setAnalysisDate(((Project) rootProject.resource()).getAnalysisDate().getTime()) .setProjectKey(((Project) rootProject.resource()).key()) diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java index 8c68e6b787f..07c53cad1f1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java @@ -31,8 +31,8 @@ import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RulePriority; import org.sonar.api.technicaldebt.batch.Characteristic; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.Constants.MeasureValueType; import org.sonar.batch.protocol.output.BatchReport; @@ -45,11 +45,11 @@ import java.io.Serializable; public class MeasuresPublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final MeasureCache measureCache; private final MetricFinder metricFinder; - public MeasuresPublisher(ResourceCache resourceCache, MeasureCache measureCache, MetricFinder metricFinder) { + public MeasuresPublisher(BatchComponentCache resourceCache, MeasureCache measureCache, MetricFinder metricFinder) { this.resourceCache = resourceCache; this.measureCache = measureCache; this.metricFinder = metricFinder; @@ -57,7 +57,7 @@ public class MeasuresPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { Iterable<Measure> batchMeasures = measureCache.byResource(resource.resource()); batchMeasures = Iterables.filter(batchMeasures, new Predicate<Measure>() { @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java index bd89b7dfe2f..c4395e755e9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java @@ -23,8 +23,8 @@ import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.BOMInputStream; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportWriter; import java.io.BufferedReader; @@ -37,15 +37,15 @@ import java.nio.charset.StandardCharsets; public class SourcePublisher implements ReportPublisherStep { - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public SourcePublisher(ResourceCache resourceCache) { + public SourcePublisher(BatchComponentCache resourceCache) { this.resourceCache = resourceCache; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { + for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java index 344ba437ce9..fd430aebc58 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java @@ -21,25 +21,24 @@ package org.sonar.batch.report; import com.google.common.base.Function; import com.google.common.collect.Iterables; +import java.util.HashSet; +import java.util.Set; +import javax.annotation.Nonnull; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.test.CoverageBlock; import org.sonar.api.test.MutableTestCase; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.TestCase; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.TestStatus; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.CoverageDetail; import org.sonar.batch.protocol.output.BatchReport.Test; import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.core.test.TestPlanBuilder; - -import javax.annotation.Nonnull; - -import java.util.HashSet; -import java.util.Set; +import org.sonar.batch.test.DefaultTestable; +import org.sonar.batch.test.TestPlanBuilder; public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { @@ -95,7 +94,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { builder.setTestName(testName); for (CoverageBlock block : testCase.coverageBlocks()) { coveredBuilder.clear(); - coveredBuilder.setFileRef(resourceCache.get(block.testable().component().key()).batchId()); + coveredBuilder.setFileRef(componentCache.get(((DefaultTestable) block.testable()).inputFile().key()).batchId()); for (int line : block.lines()) { coveredBuilder.addCoveredLine(line); } @@ -105,36 +104,36 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { } } - private final ResourceCache resourceCache; + private final BatchComponentCache componentCache; private final TestPlanBuilder testPlanBuilder; - public TestExecutionAndCoveragePublisher(ResourceCache resourceCache, TestPlanBuilder testPlanBuilder) { - this.resourceCache = resourceCache; + public TestExecutionAndCoveragePublisher(BatchComponentCache resourceCache, TestPlanBuilder testPlanBuilder) { + this.componentCache = resourceCache; this.testPlanBuilder = testPlanBuilder; } @Override public void publish(BatchReportWriter writer) { - for (final BatchResource resource : resourceCache.all()) { - if (!resource.isFile()) { + for (final BatchComponent component : componentCache.all()) { + if (!component.isFile()) { continue; } - DefaultInputFile inputFile = (DefaultInputFile) resource.inputPath(); + DefaultInputFile inputFile = (DefaultInputFile) component.inputPath(); if (inputFile.type() != Type.TEST) { continue; } - final MutableTestPlan testPlan = testPlanBuilder.get(MutableTestPlan.class, inputFile.key()); + final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component); if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) { continue; } final Set<String> testNamesWithCoverage = new HashSet<>(); - writer.writeTests(resource.batchId(), Iterables.transform(testPlan.testCases(), new TestConverter(testNamesWithCoverage))); + writer.writeTests(component.batchId(), Iterables.transform(testPlan.testCases(), new TestConverter(testNamesWithCoverage))); - writer.writeCoverageDetails(resource.batchId(), Iterables.transform(testNamesWithCoverage, new TestCoverageConverter(testPlan))); + writer.writeCoverageDetails(component.batchId(), Iterables.transform(testNamesWithCoverage, new TestCoverageConverter(testPlan))); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index a1c3bbb8202..85e2a54f232 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -46,7 +46,7 @@ import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.events.EventBus; import org.sonar.batch.index.Caches; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.index.ResourcePersister; import org.sonar.batch.issue.DefaultProjectIssues; import org.sonar.batch.issue.IssueCache; @@ -75,7 +75,8 @@ import org.sonar.batch.scan.measure.DefaultMetricFinder; import org.sonar.batch.scan.measure.DeprecatedMetricFinder; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.source.CodeColorizers; -import org.sonar.core.component.ScanGraph; +import org.sonar.batch.test.TestPlanBuilder; +import org.sonar.batch.test.TestableBuilder; import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.workflow.FunctionExecutor; import org.sonar.core.issue.workflow.IssueWorkflow; @@ -83,10 +84,6 @@ import org.sonar.core.permission.PermissionFacade; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.resource.DefaultResourcePermissions; import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; -import org.sonar.core.test.TestPlanBuilder; -import org.sonar.core.test.TestPlanPerspectiveLoader; -import org.sonar.core.test.TestableBuilder; -import org.sonar.core.test.TestablePerspectiveLoader; import org.sonar.core.user.DefaultUserFinder; public class ProjectScanContainer extends ComponentContainer { @@ -154,7 +151,7 @@ public class ProjectScanContainer extends ComponentContainer { DefaultIndex.class, DefaultFileLinesContextFactory.class, Caches.class, - ResourceCache.class, + BatchComponentCache.class, // file system InputPathCache.class, @@ -177,11 +174,8 @@ public class ProjectScanContainer extends ComponentContainer { DeprecatedMetricFinder.class, // tests - TestPlanPerspectiveLoader.class, - TestablePerspectiveLoader.class, TestPlanBuilder.class, TestableBuilder.class, - ScanGraph.create(), // lang Languages.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java index eb0976b7776..f9ff2fb6511 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java @@ -26,7 +26,7 @@ import org.sonar.api.resources.File; import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.index.ResourcePersister; import javax.annotation.Nullable; @@ -43,9 +43,9 @@ public class ComponentIndexer { private final SonarIndex sonarIndex; private final Project module; private final ResourcePersister resourcePersister; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; - public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, ResourceCache resourceCache, @Nullable ResourcePersister resourcePersister) { + public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache, @Nullable ResourcePersister resourcePersister) { this.module = module; this.languages = languages; this.sonarIndex = sonarIndex; @@ -53,7 +53,7 @@ public class ComponentIndexer { this.resourcePersister = resourcePersister; } - public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, ResourceCache resourceCache) { + public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache) { this(module, languages, sonarIndex, resourceCache, null); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java index 2eacbf5aac4..cbfd8d0c5df 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java @@ -25,7 +25,7 @@ import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import javax.annotation.CheckForNull; @@ -131,7 +131,7 @@ public class InputPathCache { } @CheckForNull - public InputPath getInputPath(BatchResource component) { + public InputPath getInputPath(BatchComponent component) { if (component.isFile()) { return getFile(component.parent().parent().resource().getEffectiveKey(), component.resource().getPath()); } else if (component.isDir()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java index 5604537b15f..c087219e1f2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java @@ -23,7 +23,7 @@ import com.google.common.collect.Maps; import org.sonar.api.issue.Issue; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import java.util.ArrayList; import java.util.Date; @@ -37,7 +37,7 @@ public class IssuesReport { private Date date; private boolean noFile; private final ReportSummary summary = new ReportSummary(); - private final Map<BatchResource, ResourceReport> resourceReportsByResource = Maps.newLinkedHashMap(); + private final Map<BatchComponent, ResourceReport> resourceReportsByResource = Maps.newLinkedHashMap(); public IssuesReport() { } @@ -70,7 +70,7 @@ public class IssuesReport { this.noFile = noFile; } - public Map<BatchResource, ResourceReport> getResourceReportsByResource() { + public Map<BatchComponent, ResourceReport> getResourceReportsByResource() { return resourceReportsByResource; } @@ -78,23 +78,23 @@ public class IssuesReport { return new ArrayList<>(resourceReportsByResource.values()); } - public List<BatchResource> getResourcesWithReport() { + public List<BatchComponent> getResourcesWithReport() { return new ArrayList<>(resourceReportsByResource.keySet()); } - public void addIssueOnResource(BatchResource resource, Issue issue, Rule rule, RulePriority severity) { + public void addIssueOnResource(BatchComponent resource, Issue issue, Rule rule, RulePriority severity) { addResource(resource); getSummary().addIssue(issue, rule, severity); resourceReportsByResource.get(resource).addIssue(issue, rule, RulePriority.valueOf(issue.severity())); } - public void addResolvedIssueOnResource(BatchResource resource, Issue issue, Rule rule, RulePriority severity) { + public void addResolvedIssueOnResource(BatchComponent resource, Issue issue, Rule rule, RulePriority severity) { addResource(resource); getSummary().addResolvedIssue(issue, rule, severity); resourceReportsByResource.get(resource).addResolvedIssue(issue, rule, RulePriority.valueOf(issue.severity())); } - private void addResource(BatchResource resource) { + private void addResource(BatchComponent resource) { if (!resourceReportsByResource.containsKey(resource)) { resourceReportsByResource.put(resource, new ResourceReport(resource)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java index 4dfcf17d249..72c48f9bb7a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java @@ -30,8 +30,8 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RulePriority; import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -44,11 +44,11 @@ public class IssuesReportBuilder { private final IssueCache issueCache; private final RuleFinder ruleFinder; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final DefaultProjectTree projectTree; private final InputPathCache inputPathCache; - public IssuesReportBuilder(IssueCache issueCache, RuleFinder ruleFinder, ResourceCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) { + public IssuesReportBuilder(IssueCache issueCache, RuleFinder ruleFinder, BatchComponentCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) { this.issueCache = issueCache; this.ruleFinder = ruleFinder; this.resourceCache = resourceCache; @@ -72,7 +72,7 @@ public class IssuesReportBuilder { for (Issue issue : issues) { Rule rule = findRule(issue); RulePriority severity = RulePriority.valueOf(issue.severity()); - BatchResource resource = resourceCache.get(issue.componentKey()); + BatchComponent resource = resourceCache.get(issue.componentKey()); if (!validate(issue, rule, resource)) { continue; } @@ -84,7 +84,7 @@ public class IssuesReportBuilder { } } - private boolean validate(Issue issue, Rule rule, BatchResource resource) { + private boolean validate(Issue issue, Rule rule, BatchComponent resource) { if (rule == null) { LOG.warn("Unknow rule for issue {}", issue); return false; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java index e48ffc3e40a..4a4329f908d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java @@ -23,7 +23,7 @@ import com.google.common.collect.Maps; import org.sonar.api.issue.Issue; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import java.util.ArrayList; import java.util.Collections; @@ -32,7 +32,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; public final class ResourceReport { - private final BatchResource resource; + private final BatchComponent resource; private final IssueVariation total = new IssueVariation(); private final Map<ReportRuleKey, RuleReport> ruleReportByRuleKey = Maps.newHashMap(); @@ -42,11 +42,11 @@ public final class ResourceReport { private Map<Rule, AtomicInteger> issuesByRule = Maps.newHashMap(); private Map<RulePriority, AtomicInteger> issuesBySeverity = Maps.newHashMap(); - public ResourceReport(BatchResource resource) { + public ResourceReport(BatchComponent resource) { this.resource = resource; } - public BatchResource getResourceNode() { + public BatchComponent getResourceNode() { return resource; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java index 049f581fa2b..9ae89557e95 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.scan.filesystem.InputPathCache; import java.io.IOException; @@ -46,7 +46,7 @@ public class SourceProvider { this.fs = fs; } - public List<String> getEscapedSource(BatchResource component) { + public List<String> getEscapedSource(BatchComponent component) { if (!component.isFile()) { // Folder return Collections.emptyList(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 399d2d3779f..33ec11e25f5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -26,8 +26,8 @@ import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.scm.BlameCommand.BlameOutput; import org.sonar.api.batch.scm.BlameLine; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Changesets.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -48,13 +48,13 @@ class DefaultBlameOutput implements BlameOutput { private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); private final BatchReportWriter writer; - private final ResourceCache componentCache; + private final BatchComponentCache componentCache; private final Set<InputFile> allFilesToBlame = new HashSet<>(); private ProgressReport progressReport; private int count; private int total; - DefaultBlameOutput(BatchReportWriter writer, ResourceCache componentCache, List<InputFile> filesToBlame) { + DefaultBlameOutput(BatchReportWriter writer, BatchComponentCache componentCache, List<InputFile> filesToBlame) { this.writer = writer; this.componentCache = componentCache; this.allFilesToBlame.addAll(filesToBlame); @@ -75,7 +75,7 @@ class DefaultBlameOutput implements BlameOutput { return; } - BatchResource batchComponent = componentCache.get(file); + BatchComponent batchComponent = componentCache.get(file); Builder scmBuilder = BatchReport.Changesets.newBuilder(); scmBuilder.setComponentRef(batchComponent.batchId()); Map<String, Integer> changesetsIdByRevision = new HashMap<>(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java index 24492bbdc78..a74ad87c3e1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -29,7 +29,7 @@ import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.input.FileData; import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.report.ReportPublisher; @@ -46,11 +46,11 @@ public final class ScmSensor implements Sensor { private final ScmConfiguration configuration; private final FileSystem fs; private final ProjectRepositories projectReferentials; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ReportPublisher publishReportJob; public ScmSensor(ProjectDefinition projectDefinition, ScmConfiguration configuration, - ProjectRepositories projectReferentials, FileSystem fs, InputPathCache inputPathCache, ResourceCache resourceCache, + ProjectRepositories projectReferentials, FileSystem fs, InputPathCache inputPathCache, BatchComponentCache resourceCache, ReportPublisher publishReportJob) { this.projectDefinition = projectDefinition; this.configuration = configuration; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java index cf4b285971a..208dc809210 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java @@ -52,9 +52,9 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.source.Symbol; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.BatchResource; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; @@ -76,12 +76,12 @@ public class DefaultSensorStorage implements SensorStorage { private final DefaultIndex sonarIndex; private final CoverageExclusions coverageExclusions; private final DuplicationCache duplicationCache; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final ReportPublisher reportPublisher; public DefaultSensorStorage(MetricFinder metricFinder, Project project, ModuleIssues moduleIssues, Settings settings, FileSystem fs, ActiveRules activeRules, DuplicationCache duplicationCache, DefaultIndex sonarIndex, - CoverageExclusions coverageExclusions, ResourceCache resourceCache, ReportPublisher reportPublisher) { + CoverageExclusions coverageExclusions, BatchComponentCache resourceCache, ReportPublisher reportPublisher) { this.metricFinder = metricFinder; this.project = project; this.moduleIssues = moduleIssues; @@ -178,7 +178,7 @@ public class DefaultSensorStorage implements SensorStorage { } private File getFile(InputFile file) { - BatchResource r = resourceCache.get(file); + BatchComponent r = resourceCache.get(file); if (r == null) { throw new IllegalStateException("Provided input file is not indexed"); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java index 7581b44b14d..0d19be3cdea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java @@ -25,7 +25,7 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.report.ReportPublisher; import org.sonar.colorizer.CodeColorizer; @@ -37,10 +37,10 @@ import org.sonar.colorizer.CodeColorizer; public final class CodeColorizerSensor implements Sensor { private final ReportPublisher reportPublisher; - private final ResourceCache resourceCache; + private final BatchComponentCache resourceCache; private final CodeColorizers codeColorizers; - public CodeColorizerSensor(ReportPublisher reportPublisher, ResourceCache resourceCache, CodeColorizers codeColorizers) { + public CodeColorizerSensor(ReportPublisher reportPublisher, BatchComponentCache resourceCache, CodeColorizers codeColorizers) { this.reportPublisher = reportPublisher; this.resourceCache = resourceCache; this.codeColorizers = codeColorizers; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java index 741346dd99b..e03531d243e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java @@ -23,9 +23,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; import org.sonar.api.source.Highlightable; -import org.sonar.batch.deprecated.InputFileComponent; /** * @since 3.6 @@ -47,11 +45,6 @@ public class DefaultHighlightable implements Highlightable { return new DefaultHighlightingBuilder(defaultHighlighting); } - @Override - public Component component() { - return new InputFileComponent(inputFile); - } - private static class DefaultHighlightingBuilder implements HighlightingBuilder { private final DefaultHighlighting defaultHighlighting; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java index 037913f06cd..f65cb609c21 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java @@ -21,9 +21,7 @@ package org.sonar.batch.source; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.deprecated.InputFileComponent; import org.sonar.batch.sensor.DefaultSensorStorage; public class DefaultSymbolizable implements Symbolizable { @@ -37,11 +35,6 @@ public class DefaultSymbolizable implements Symbolizable { } @Override - public Component component() { - return new InputFileComponent(inputFile); - } - - @Override public SymbolTableBuilder newSymbolTableBuilder() { return new DefaultSymbolTable.Builder(inputFile); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java index fa9326a1604..2a1a7d3ac5e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java @@ -19,46 +19,29 @@ */ package org.sonar.batch.source; -import com.google.common.collect.ImmutableSet; +import javax.annotation.CheckForNull; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.source.Highlightable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Set; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; public class HighlightableBuilder extends PerspectiveBuilder<Highlightable> { - private static final Set<String> SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); - private final ResourceCache cache; private final SensorStorage sensorStorage; - public HighlightableBuilder(ResourceCache cache, SensorStorage sensorStorage) { + public HighlightableBuilder(SensorStorage sensorStorage) { super(Highlightable.class); - this.cache = cache; this.sensorStorage = sensorStorage; } @CheckForNull @Override - public Highlightable loadPerspective(Class<Highlightable> perspectiveClass, Component component) { - boolean supported = SUPPORTED_QUALIFIERS.contains(component.qualifier()); - if (supported && component instanceof ResourceComponent) { - BatchResource batchComponent = cache.get(component.key()); - if (batchComponent != null) { - InputFile path = (InputFile) batchComponent.inputPath(); - if (path != null) { - return new DefaultHighlightable((DefaultInputFile) path, sensorStorage); - } - } + public Highlightable loadPerspective(Class<Highlightable> perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile path = (InputFile) component.inputPath(); + return new DefaultHighlightable((DefaultInputFile) path, sensorStorage); } return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java index 212c31d87b4..05ab9db0a45 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java @@ -20,46 +20,29 @@ package org.sonar.batch.source; -import com.google.common.collect.ImmutableSet; +import javax.annotation.CheckForNull; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ResourceComponent; - -import javax.annotation.CheckForNull; - -import java.util.Set; public class SymbolizableBuilder extends PerspectiveBuilder<Symbolizable> { - private static final Set<String> SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); - private final ResourceCache cache; private final DefaultSensorStorage sensorStorage; - public SymbolizableBuilder(ResourceCache cache, DefaultSensorStorage sensorStorage) { + public SymbolizableBuilder(DefaultSensorStorage sensorStorage) { super(Symbolizable.class); - this.cache = cache; this.sensorStorage = sensorStorage; } @CheckForNull @Override - public Symbolizable loadPerspective(Class<Symbolizable> perspectiveClass, Component component) { - boolean supported = SUPPORTED_QUALIFIERS.contains(component.qualifier()); - if (supported && component instanceof ResourceComponent) { - BatchResource batchComponent = cache.get(component.key()); - if (batchComponent != null) { - InputFile path = (InputFile) batchComponent.inputPath(); - if (path != null) { - return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage); - } - } + public Symbolizable loadPerspective(Class<Symbolizable> perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile path = (InputFile) component.inputPath(); + return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage); } return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java new file mode 100644 index 00000000000..b65526824f9 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java @@ -0,0 +1,54 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import java.util.List; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.TestCase; +import org.sonar.api.test.Testable; + +public class DefaultCoverageBlock implements CoverageBlock { + + private final TestCase testCase; + private final DefaultInputFile testable; + private final List<Integer> lines; + + public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List<Integer> lines) { + this.testCase = testCase; + this.testable = testable; + this.lines = lines; + } + + @Override + public TestCase testCase() { + return testCase; + } + + @Override + public Testable testable() { + return new DefaultTestable(testable); + } + + @Override + public List<Integer> lines() { + return lines; + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java new file mode 100644 index 00000000000..6cf1af728da --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java @@ -0,0 +1,164 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import com.google.common.base.Preconditions; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.MutableTestCase; +import org.sonar.api.test.TestPlan; +import org.sonar.api.test.Testable; +import org.sonar.api.test.exception.CoverageAlreadyExistsException; +import org.sonar.api.test.exception.IllegalDurationException; + +public class DefaultTestCase implements MutableTestCase { + + private final DefaultTestPlan testPlan; + private String type; + private Long durationInMs; + private Status status; + private String name; + private String message; + private String stackTrace; + private Map<DefaultInputFile, CoverageBlock> coverageBlocksByTestedFile = new LinkedHashMap<>(); + + public DefaultTestCase(DefaultTestPlan testPlan) { + this.testPlan = testPlan; + } + + @Override + public String type() { + return type; + } + + @Override + public MutableTestCase setType(@Nullable String s) { + this.type = s; + return this; + } + + @Override + public Long durationInMs() { + return durationInMs; + } + + @Override + public MutableTestCase setDurationInMs(@Nullable Long l) { + if (l != null && l < 0) { + throw new IllegalDurationException("Test duration must be positive (got: " + l + ")"); + } + this.durationInMs = l; + return this; + } + + @Override + public Status status() { + return status; + } + + @Override + public MutableTestCase setStatus(@Nullable Status s) { + this.status = s; + ; + return this; + } + + @Override + public String name() { + return name; + } + + public MutableTestCase setName(String s) { + this.name = s; + return this; + } + + @Override + public String message() { + return message; + } + + @Override + public MutableTestCase setMessage(String s) { + this.message = s; + return this; + } + + @Override + public String stackTrace() { + return stackTrace; + } + + @Override + public MutableTestCase setStackTrace(String s) { + this.stackTrace = s; + return this; + } + + @Override + public MutableTestCase setCoverageBlock(Testable testable, List<Integer> lines) { + DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); + return setCoverageBlock(coveredFile, lines); + } + + @Override + public MutableTestCase setCoverageBlock(InputFile mainFile, List<Integer> lines) { + Preconditions.checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file"); + DefaultInputFile coveredFile = (DefaultInputFile) mainFile; + if (coverageBlocksByTestedFile.containsKey(coveredFile)) { + throw new CoverageAlreadyExistsException("The link between " + name() + " and " + coveredFile.key() + " already exists"); + } + coverageBlocksByTestedFile.put(coveredFile, new DefaultCoverageBlock(this, coveredFile, lines)); + return this; + } + + @Override + public TestPlan testPlan() { + return testPlan; + } + + @Override + public boolean doesCover() { + return !coverageBlocksByTestedFile.isEmpty(); + } + + @Override + public int countCoveredLines() { + throw new UnsupportedOperationException("Not supported since SQ 5.2"); + } + + @Override + public Iterable<CoverageBlock> coverageBlocks() { + return coverageBlocksByTestedFile.values(); + } + + @Override + public CoverageBlock coverageBlock(final Testable testable) { + DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); + return coverageBlocksByTestedFile.get(coveredFile); + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java new file mode 100644 index 00000000000..79adc923c24 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java @@ -0,0 +1,57 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import com.google.common.collect.Lists; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.CheckForNull; +import org.sonar.api.test.MutableTestCase; +import org.sonar.api.test.MutableTestPlan; + +public class DefaultTestPlan implements MutableTestPlan { + private List<MutableTestCase> testCases = new ArrayList<>(); + + @Override + @CheckForNull + public Iterable<MutableTestCase> testCasesByName(String name) { + List<MutableTestCase> result = Lists.newArrayList(); + for (MutableTestCase testCase : testCases()) { + if (name.equals(testCase.name())) { + result.add(testCase); + } + } + return result; + } + + @Override + public MutableTestCase addTestCase(String name) { + DefaultTestCase testCase = new DefaultTestCase(this); + testCase.setName(name); + testCases.add(testCase); + return testCase; + } + + @Override + public Iterable<MutableTestCase> testCases() { + return testCases; + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java new file mode 100644 index 00000000000..6bfe739b196 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java @@ -0,0 +1,86 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.CoverageBlock; +import org.sonar.api.test.MutableTestable; +import org.sonar.api.test.TestCase; + +public class DefaultTestable implements MutableTestable { + + private final DefaultInputFile inputFile; + + public DefaultTestable(DefaultInputFile inputFile) { + this.inputFile = inputFile; + } + + public DefaultInputFile inputFile() { + return inputFile; + } + + @Override + public List<TestCase> testCases() { + throw unsupported(); + } + + @Override + public TestCase testCaseByName(final String name) { + throw unsupported(); + } + + @Override + public int countTestCasesOfLine(Integer line) { + throw unsupported(); + } + + @Override + public Map<Integer, Integer> testCasesByLines() { + throw unsupported(); + } + + @Override + public List<TestCase> testCasesOfLine(int line) { + throw unsupported(); + } + + @Override + public SortedSet<Integer> testedLines() { + throw unsupported(); + } + + @Override + public CoverageBlock coverageBlock(final TestCase testCase) { + throw unsupported(); + } + + @Override + public Iterable<CoverageBlock> coverageBlocks() { + throw unsupported(); + } + + private UnsupportedOperationException unsupported() { + return new UnsupportedOperationException("No more available since SQ 5.2"); + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java new file mode 100644 index 00000000000..296bc8713bb --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java @@ -0,0 +1,54 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.CheckForNull; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.test.MutableTestPlan; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; + +public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> { + + private Map<InputFile, DefaultTestPlan> testPlanByFile = new HashMap<>(); + + public TestPlanBuilder() { + super(MutableTestPlan.class); + } + + @CheckForNull + @Override + public MutableTestPlan loadPerspective(Class<MutableTestPlan> perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputPath(); + if (inputFile.type() == Type.TEST) { + if (!testPlanByFile.containsKey(inputFile)) { + testPlanByFile.put(inputFile, new DefaultTestPlan()); + } + return testPlanByFile.get(inputFile); + } + } + return null; + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java new file mode 100644 index 00000000000..e1927ecdba6 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.test; + +import javax.annotation.CheckForNull; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.test.MutableTestable; +import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; +import org.sonar.batch.index.BatchComponent; + +public class TestableBuilder extends PerspectiveBuilder<MutableTestable> { + + public TestableBuilder() { + super(MutableTestable.class); + } + + @CheckForNull + @Override + public MutableTestable loadPerspective(Class<MutableTestable> perspectiveClass, BatchComponent component) { + if (component.isFile()) { + InputFile inputFile = (InputFile) component.inputPath(); + if (inputFile.type() == Type.MAIN) { + return new DefaultTestable((DefaultInputFile) inputFile); + } + } + return null; + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java new file mode 100644 index 00000000000..0c5f5e473ee --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.batch.test; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java index f4aef8284d4..7028bfcceba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cpd/index/IndexFactoryTest.java @@ -27,7 +27,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrap.DefaultAnalysisMode; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.duplication.DuplicationDao; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ public class IndexFactoryTest { project = new Project("foo"); settings = new Settings(); analysisMode = mock(DefaultAnalysisMode.class); - factory = new IndexFactory(analysisMode, settings, mock(DuplicationDao.class), mock(DatabaseSession.class), new ResourceCache()); + factory = new IndexFactory(analysisMode, settings, mock(DuplicationDao.class), mock(DatabaseSession.class), new BatchComponentCache()); logger = mock(Logger.class); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java new file mode 100644 index 00000000000..917a7339ba7 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java @@ -0,0 +1,44 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.batch.deprecated.perspectives; + +import org.junit.Test; +import org.sonar.api.component.Perspective; +import org.sonar.batch.index.BatchComponent; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PerspectiveBuilderTest { + @Test + public void testGetPerspectiveClass() throws Exception { + PerspectiveBuilder<FakePerspective> builder = new PerspectiveBuilder<FakePerspective>(FakePerspective.class) { + @Override + public FakePerspective loadPerspective(Class<FakePerspective> perspectiveClass, BatchComponent component) { + return null; + } + }; + + assertThat(builder.getPerspectiveClass()).isEqualTo(FakePerspective.class); + } + + static interface FakePerspective extends Perspective { + + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java index 461a9a4d7f1..4262d004d8b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java @@ -26,10 +26,10 @@ import org.sonar.api.resources.Resource; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class ResourceCacheTest { +public class BatchComponentCacheTest { @Test public void should_cache_resource() { - ResourceCache cache = new ResourceCache(); + BatchComponentCache cache = new BatchComponentCache(); String componentKey = "struts:src/org/struts/Action.java"; Resource resource = File.create("org/struts/Action.java").setEffectiveKey(componentKey); cache.add(resource, null); @@ -40,7 +40,7 @@ public class ResourceCacheTest { @Test public void should_fail_if_missing_component_key() { - ResourceCache cache = new ResourceCache(); + BatchComponentCache cache = new BatchComponentCache(); Resource resource = File.create("org/struts/Action.java").setEffectiveKey(null); try { cache.add(resource, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java index bab64fa049b..29cdc0e6f24 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java @@ -68,7 +68,7 @@ public class DefaultIndexTest { ruleFinder = mock(RuleFinder.class); DefaultProjectTree projectTree = mock(DefaultProjectTree.class); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); index = new DefaultIndex(resourceCache, projectTree, metricFinder, mock(MeasureCache.class)); baseDir = temp.newFolder(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java index 4ef7d6173e6..4c83e9da457 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java @@ -19,6 +19,10 @@ */ package org.sonar.batch.index; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import javax.persistence.Query; import org.apache.ibatis.session.SqlSession; import org.junit.Before; import org.junit.Rule; @@ -38,16 +42,9 @@ import org.sonar.api.security.ResourcePermissions; import org.sonar.batch.DefaultProjectTree; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.core.component.ComponentDto; -import org.sonar.core.component.ScanGraph; import org.sonar.core.component.db.ComponentMapper; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import javax.persistence.Query; - -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -64,7 +61,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { public TemporaryFolder temp = new TemporaryFolder(); private Project singleProject, singleCopyProject, multiModuleProject, moduleA, moduleB, moduleB1, existingProject; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private ResourcePersister persister; @@ -74,7 +71,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { @Before public void before() throws ParseException { - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); singleProject = newProject("foo", "java"); @@ -106,7 +103,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { projectTree = mock(DefaultProjectTree.class); permissions = mock(ResourcePermissions.class); - persister = new ResourcePersister(getSession(), permissions, resourceCache, mock(ScanGraph.class)); + persister = new ResourcePersister(getSession(), permissions, resourceCache); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java index 26d1fccd060..42843ddd8ec 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java @@ -19,14 +19,13 @@ */ package org.sonar.batch.issue; +import java.util.Arrays; +import java.util.List; import org.junit.Test; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.Project; - -import java.util.Arrays; -import java.util.List; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -37,7 +36,7 @@ public class DefaultIssuableTest { ModuleIssues moduleIssues = mock(ModuleIssues.class); IssueCache cache = mock(IssueCache.class); Project project = mock(Project.class); - Component component = mock(Component.class); + BatchComponent component = mock(BatchComponent.class); @Test public void test_unresolved_issues() throws Exception { diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java index ac390520311..c124a40fc49 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java @@ -21,12 +21,11 @@ package org.sonar.batch.issue; import org.junit.Test; import org.mockito.Mockito; -import org.sonar.api.component.Component; import org.sonar.api.issue.Issuable; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.batch.DefaultProjectTree; -import org.sonar.core.component.ResourceComponent; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -40,22 +39,20 @@ public class IssuableFactoryTest { @Test public void file_should_be_issuable() { IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); - Component component = new ResourceComponent(File.create("foo/bar.c").setEffectiveKey("foo/bar.c")); + BatchComponent component = new BatchComponent(1, File.create("foo/bar.c").setEffectiveKey("foo/bar.c"), null); Issuable issuable = factory.loadPerspective(Issuable.class, component); assertThat(issuable).isNotNull(); - assertThat(issuable.component()).isSameAs(component); assertThat(issuable.issues()).isEmpty(); } @Test public void project_should_be_issuable() { IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); - Component component = new ResourceComponent(new Project("Foo").setEffectiveKey("foo")); + BatchComponent component = new BatchComponent(1, new Project("Foo").setEffectiveKey("foo"), null); Issuable issuable = factory.loadPerspective(Issuable.class, component); assertThat(issuable).isNotNull(); - assertThat(issuable.component()).isSameAs(component); assertThat(issuable.issues()).isEmpty(); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java index 9ca6dd40771..5db240ddeb5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.Settings; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.File; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import java.util.Arrays; @@ -40,7 +40,7 @@ import static org.mockito.Mockito.when; public class DefaultPostJobContextTest { private IssueCache issueCache; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private AnalysisMode analysisMode; private DefaultPostJobContext context; private Settings settings; @@ -48,7 +48,7 @@ public class DefaultPostJobContextTest { @Before public void prepare() { issueCache = mock(IssueCache.class); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); analysisMode = mock(AnalysisMode.class); settings = new Settings(); context = new DefaultPostJobContext(settings, analysisMode, issueCache, resourceCache); diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java index 759471b4677..12194f753ca 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java @@ -39,7 +39,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.core.qualitygate.db.QualityGateConditionDto; import org.sonar.core.timemachine.Periods; @@ -70,7 +70,7 @@ public class QualityGateVerifierTest { Periods periods; I18n i18n; Durations durations; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; @Before public void before() { @@ -94,7 +94,7 @@ public class QualityGateVerifierTest { project = new Project("foo"); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); resourceCache.add(project, null).setSnapshot(snapshot); verifier = new QualityGateVerifier(qualityGate, resourceCache, periods, i18n, durations); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java index 2d2a97e234d..ead29534e98 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java @@ -32,7 +32,7 @@ import org.sonar.api.resources.Directory; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.utils.DateUtils; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.Constants.ComponentLinkType; import org.sonar.batch.protocol.Constants.EventCategory; import org.sonar.batch.protocol.output.BatchReport.Component; @@ -54,7 +54,7 @@ public class ComponentsPublisherTest { public TemporaryFolder temp = new TemporaryFolder(); private ProjectReactor reactor; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; private ComponentsPublisher publisher; private EventCache eventCache; @@ -62,7 +62,7 @@ public class ComponentsPublisherTest { public void prepare() { reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); reactor.getRoot().properties().put(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0"); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); eventCache = mock(EventCache.class); publisher = new ComponentsPublisher(reactor, resourceCache, eventCache); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java index f799843baba..b8e4b7acfb3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java @@ -29,7 +29,7 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Coverage; import org.sonar.batch.protocol.output.BatchReportReader; @@ -60,7 +60,7 @@ public class CoveragePublisherTest { @Before public void prepare() { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java index a3536f2ada1..4c64bd4b2c9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java @@ -27,7 +27,7 @@ import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.api.resources.Project; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -51,7 +51,7 @@ public class DuplicationsPublisherTest { @Before public void prepare() { - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); Project p = new Project("foo"); resourceCache.add(p, null); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java index ecfd2377b17..f4299ae0df6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java @@ -31,7 +31,7 @@ import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Duration; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.output.BatchReport.Metadata; import org.sonar.batch.protocol.output.BatchReportReader; @@ -59,7 +59,7 @@ public class IssuesPublisherTest { public void prepare() { ProjectDefinition root = ProjectDefinition.create().setKey("foo"); Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java index bc22f032a19..658cafcc62d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java @@ -36,7 +36,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RulePriority; import org.sonar.api.technicaldebt.batch.Characteristic; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.scan.measure.MeasureCache; @@ -66,7 +66,7 @@ public class MeasuresPublisherTest { @Before public void prepare() { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); resourceCache.add(sampleFile, null); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java index 4a6e27960d2..dcb0438619f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java @@ -30,7 +30,7 @@ import org.sonar.api.platform.Server; import org.sonar.api.utils.TempFolder; import org.sonar.batch.bootstrap.DefaultAnalysisMode; import org.sonar.batch.bootstrap.ServerClient; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.jpa.test.AbstractDbUnitTestCase; import static org.mockito.Mockito.mock; @@ -41,7 +41,7 @@ public class ReportPublisherTest extends AbstractDbUnitTestCase { private DefaultAnalysisMode mode; - ResourceCache resourceCache = mock(ResourceCache.class); + BatchComponentCache resourceCache = mock(BatchComponentCache.class); private ProjectReactor reactor; diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java index bfe6067b692..0125a4bb5ba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.protocol.output.BatchReportWriter; import java.io.File; @@ -54,7 +54,7 @@ public class SourcePublisherTest { @Before public void prepare() throws IOException { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); - ResourceCache resourceCache = new ResourceCache(); + BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php"); sampleFile.setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java index b5b8732d5f9..df55eddc1f7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java @@ -35,8 +35,8 @@ 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.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; +import org.sonar.batch.index.BatchComponentCache; import java.io.File; import java.io.IOException; @@ -100,8 +100,8 @@ public class ComponentIndexerTest { } private ComponentIndexer createIndexer(Languages languages) { - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(any(Resource.class))).thenReturn(new BatchResource(1, org.sonar.api.resources.File.create("foo.php"), null)); + BatchComponentCache resourceCache = mock(BatchComponentCache.class); + when(resourceCache.get(any(Resource.class))).thenReturn(new BatchComponent(1, org.sonar.api.resources.File.create("foo.php"), null)); return new ComponentIndexer(project, languages, sonarIndex, resourceCache); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java index e3135e79a34..b03d9baf3bd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java @@ -46,7 +46,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.sensor.coverage.CoverageExclusions; @@ -74,7 +74,7 @@ public class DefaultSensorStorageTest { private Project project; private DefaultIndex sonarIndex; - private ResourceCache resourceCache; + private BatchComponentCache resourceCache; @Before public void prepare() throws Exception { @@ -89,7 +89,7 @@ public class DefaultSensorStorageTest { sonarIndex = mock(DefaultIndex.class); CoverageExclusions coverageExclusions = mock(CoverageExclusions.class); when(coverageExclusions.accept(any(Resource.class), any(Measure.class))).thenReturn(true); - resourceCache = new ResourceCache(); + resourceCache = new BatchComponentCache(); sensorStorage = new DefaultSensorStorage(metricFinder, project, moduleIssues, settings, fs, activeRules, mock(DuplicationCache.class), sonarIndex, coverageExclusions, resourceCache, mock(ReportPublisher.class)); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java index e98f3bad906..3d05b7eb3ed 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java @@ -20,42 +20,34 @@ package org.sonar.batch.source; import org.junit.Test; -import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.component.Component; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.source.Highlightable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.component.ResourceComponent; +import org.sonar.batch.index.BatchComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class HighlightableBuilderTest { @Test public void should_load_default_perspective() { Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); - Component component = new ResourceComponent(file); + BatchComponent component = new BatchComponent(1, file, null); - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(file.getEffectiveKey())).thenReturn(new BatchResource(1, file, null).setInputPath(new DefaultInputFile("myproject", "path/to/foo.c"))); - HighlightableBuilder builder = new HighlightableBuilder(resourceCache, mock(SensorStorage.class)); + HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class)); Highlightable perspective = builder.loadPerspective(Highlightable.class, component); assertThat(perspective).isNotNull().isInstanceOf(DefaultHighlightable.class); - assertThat(perspective.component().key()).isEqualTo(component.key()); } @Test public void project_should_not_be_highlightable() { - Component component = new ResourceComponent(new Project("struts").setEffectiveKey("org.struts")); + BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null); - HighlightableBuilder builder = new HighlightableBuilder(mock(ResourceCache.class), mock(SensorStorage.class)); + HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class)); Highlightable perspective = builder.loadPerspective(Highlightable.class, component); assertThat(perspective).isNull(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java index 8a1d3cbe580..9b29c6ff3c3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java @@ -21,44 +21,35 @@ package org.sonar.batch.source; import org.junit.Test; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.source.Symbolizable; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.BatchComponent; import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.core.component.ResourceComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class SymbolizableBuilderTest { @Test public void should_load_perspective() { Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); - Component component = new ResourceComponent(file); + BatchComponent component = new BatchComponent(1, file, null); - ResourceCache resourceCache = mock(ResourceCache.class); - when(resourceCache.get(file.getEffectiveKey())).thenReturn(new BatchResource(1, file, null).setInputPath(new DefaultInputFile("myproject", "path/to/foo.c"))); - - SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(resourceCache, mock(DefaultSensorStorage.class)); + SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(mock(DefaultSensorStorage.class)); Perspective perspective = perspectiveBuilder.loadPerspective(Symbolizable.class, component); assertThat(perspective).isInstanceOf(Symbolizable.class); - assertThat(perspective.component().key()).isEqualTo(component.key()); } @Test public void project_should_not_be_highlightable() { - Component component = new ResourceComponent(new Project("struts").setEffectiveKey("org.struts")); + BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null); - SymbolizableBuilder builder = new SymbolizableBuilder(mock(ResourceCache.class), mock(DefaultSensorStorage.class)); + SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class)); Perspective perspective = builder.loadPerspective(Symbolizable.class, component); assertThat(perspective).isNull(); |