aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-01-17 17:45:09 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-01-27 16:26:30 +0100
commiteea589c564a924993e8edba9d8fa9691e756bce4 (patch)
treec112f6d41d7f4dfeb7ad8d14f895e1b879a68411 /sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking
parent211a993bd85b5d12ace1686b133677381da8c597 (diff)
downloadsonarqube-eea589c564a924993e8edba9d8fa9691e756bce4.tar.gz
sonarqube-eea589c564a924993e8edba9d8fa9691e756bce4.zip
Refactor resources API
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java29
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java29
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java15
3 files changed, 39 insertions, 34 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java
index 9c3da91e702..99c47fb064b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java
@@ -20,15 +20,16 @@
package org.sonar.scanner.issue.tracking;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.resources.Project;
+import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.index.BatchComponent;
-import org.sonar.scanner.index.BatchComponentCache;
+import org.sonar.scanner.ProjectAnalysisInfo;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.IssueTransformer;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.report.ReportPublisher;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.util.ProgressReport;
import javax.annotation.Nullable;
@@ -41,23 +42,23 @@ import java.util.concurrent.TimeUnit;
@ScannerSide
public class IssueTransition {
private final IssueCache issueCache;
- private final BatchComponentCache componentCache;
+ private final InputComponentStore inputComponentStore;
private final ReportPublisher reportPublisher;
private final Date analysisDate;
@Nullable
private final LocalIssueTracking localIssueTracking;
- public IssueTransition(BatchComponentCache componentCache, IssueCache issueCache, ReportPublisher reportPublisher,
+ public IssueTransition(InputComponentStore inputComponentCache, ProjectAnalysisInfo projectAnalysisInfo, IssueCache issueCache, ReportPublisher reportPublisher,
@Nullable LocalIssueTracking localIssueTracking) {
- this.componentCache = componentCache;
+ this.inputComponentStore = inputComponentCache;
this.issueCache = issueCache;
this.reportPublisher = reportPublisher;
this.localIssueTracking = localIssueTracking;
- this.analysisDate = ((Project) componentCache.getRoot().resource()).getAnalysisDate();
+ this.analysisDate = projectAnalysisInfo.analysisDate();
}
- public IssueTransition(BatchComponentCache componentCache, IssueCache issueCache, ReportPublisher reportPublisher) {
- this(componentCache, issueCache, reportPublisher, null);
+ public IssueTransition(InputComponentStore inputComponentCache, ProjectAnalysisInfo projectAnalysisInfo, IssueCache issueCache, ReportPublisher reportPublisher) {
+ this(inputComponentCache, projectAnalysisInfo, issueCache, reportPublisher, null);
}
public void execute() {
@@ -66,7 +67,7 @@ public class IssueTransition {
}
ScannerReportReader reader = new ScannerReportReader(reportPublisher.getReportDir());
- int nbComponents = componentCache.all().size();
+ int nbComponents = inputComponentStore.all().size();
if (nbComponents == 0) {
return;
@@ -77,8 +78,8 @@ public class IssueTransition {
int count = 0;
try {
- for (BatchComponent component : componentCache.all()) {
- trackIssues(reader, component);
+ for (InputComponent component : inputComponentStore.all()) {
+ trackIssues(reader, (DefaultInputComponent) component);
count++;
progressReport.message(count + "/" + nbComponents + " components tracked");
}
@@ -87,7 +88,7 @@ public class IssueTransition {
}
}
- public void trackIssues(ScannerReportReader reader, BatchComponent component) {
+ public void trackIssues(ScannerReportReader reader, DefaultInputComponent component) {
// raw issues = all the issues created by rule engines during this module scan and not excluded by filters
List<ScannerReport.Issue> rawIssues = new LinkedList<>();
try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(component.batchId())) {
@@ -110,7 +111,7 @@ public class IssueTransition {
}
}
- private static List<TrackedIssue> doTransition(List<ScannerReport.Issue> rawIssues, BatchComponent component) {
+ private static List<TrackedIssue> doTransition(List<ScannerReport.Issue> rawIssues, InputComponent component) {
List<TrackedIssue> issues = new ArrayList<>(rawIssues.size());
for (ScannerReport.Issue issue : rawIssues) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java
index e83785cf44b..465d4bbce7c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java
@@ -20,6 +20,8 @@
package org.sonar.scanner.issue.tracking;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -30,17 +32,18 @@ import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
+import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.InputComponentTree;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.resources.ResourceUtils;
import org.sonar.core.issue.tracking.Input;
import org.sonar.core.issue.tracking.Tracker;
import org.sonar.core.issue.tracking.Tracking;
import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.index.BatchComponent;
import org.sonar.scanner.issue.IssueTransformer;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.repository.ProjectRepositories;
@@ -52,13 +55,15 @@ public class LocalIssueTracking {
private final ActiveRules activeRules;
private final ServerIssueRepository serverIssueRepository;
private final DefaultAnalysisMode mode;
+ private final InputComponentTree componentTree;
private boolean hasServerAnalysis;
- public LocalIssueTracking(Tracker<TrackedIssue, ServerIssueFromWs> tracker, ServerLineHashesLoader lastLineHashes,
+ public LocalIssueTracking(Tracker<TrackedIssue, ServerIssueFromWs> tracker, ServerLineHashesLoader lastLineHashes, InputComponentTree componentTree,
ActiveRules activeRules, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) {
this.tracker = tracker;
this.lastLineHashes = lastLineHashes;
+ this.componentTree = componentTree;
this.serverIssueRepository = serverIssueRepository;
this.mode = mode;
this.activeRules = activeRules;
@@ -71,7 +76,7 @@ public class LocalIssueTracking {
}
}
- public List<TrackedIssue> trackIssues(BatchComponent component, Collection<ScannerReport.Issue> reportIssues, Date analysisDate) {
+ public List<TrackedIssue> trackIssues(InputComponent component, Collection<ScannerReport.Issue> reportIssues, Date analysisDate) {
List<TrackedIssue> trackedIssues = new LinkedList<>();
if (hasServerAnalysis) {
// all the issues that are not closed in db before starting this module scan, including manual issues
@@ -96,7 +101,8 @@ public class LocalIssueTracking {
}
}
- if (hasServerAnalysis && ResourceUtils.isRootProject(component.resource())) {
+ if (hasServerAnalysis && componentTree.getParent(component) == null) {
+ Preconditions.checkState(component instanceof InputModule, "Object without parent is of type: " + component.getClass());
// issues that relate to deleted components
addIssuesOnDeletedComponents(trackedIssues);
}
@@ -127,9 +133,9 @@ public class LocalIssueTracking {
return new IssueTrackingInput<>(rIssues, baseHashes);
}
- private boolean shouldCopyServerIssues(BatchComponent component) {
+ private boolean shouldCopyServerIssues(InputComponent component) {
if (!mode.scanAllFiles() && component.isFile()) {
- InputFile inputFile = (InputFile) component.inputComponent();
+ InputFile inputFile = (InputFile) component;
if (inputFile.status() == Status.SAME) {
return true;
}
@@ -155,19 +161,16 @@ public class LocalIssueTracking {
}
@CheckForNull
- private SourceHashHolder loadSourceHashes(BatchComponent component) {
+ private SourceHashHolder loadSourceHashes(InputComponent component) {
SourceHashHolder sourceHashHolder = null;
if (component.isFile()) {
- DefaultInputFile file = (DefaultInputFile) component.inputComponent();
- if (file == null) {
- throw new IllegalStateException("Resource " + component.resource() + " was not found in InputPath cache");
- }
+ DefaultInputFile file = (DefaultInputFile) component;
sourceHashHolder = new SourceHashHolder(file, lastLineHashes);
}
return sourceHashHolder;
}
- private Collection<ServerIssueFromWs> loadServerIssues(BatchComponent component) {
+ private Collection<ServerIssueFromWs> loadServerIssues(InputComponent component) {
Collection<ServerIssueFromWs> serverIssues = new ArrayList<>();
for (org.sonar.scanner.protocol.input.ScannerInput.ServerIssue previousIssue : serverIssueRepository.byComponent(component)) {
serverIssues.add(new ServerIssueFromWs(previousIssue));
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java
index 116955cc6ea..f706da4e545 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java
@@ -22,16 +22,17 @@ package org.sonar.scanner.issue.tracking;
import com.google.common.base.Function;
import javax.annotation.Nullable;
import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.core.component.ComponentKeys;
-import org.sonar.scanner.index.BatchComponent;
-import org.sonar.scanner.index.BatchComponentCache;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
import org.sonar.scanner.repository.ServerIssuesLoader;
import org.sonar.scanner.scan.ImmutableProjectReactor;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.storage.Storage;
import org.sonar.scanner.storage.Storages;
@@ -46,9 +47,9 @@ public class ServerIssueRepository {
private Storage<ServerIssue> issuesCache;
private final ServerIssuesLoader previousIssuesLoader;
private final ImmutableProjectReactor reactor;
- private final BatchComponentCache resourceCache;
+ private final InputComponentStore resourceCache;
- public ServerIssueRepository(Storages caches, ServerIssuesLoader previousIssuesLoader, ImmutableProjectReactor reactor, BatchComponentCache resourceCache) {
+ public ServerIssueRepository(Storages caches, ServerIssuesLoader previousIssuesLoader, ImmutableProjectReactor reactor, InputComponentStore resourceCache) {
this.caches = caches;
this.previousIssuesLoader = previousIssuesLoader;
this.reactor = reactor;
@@ -63,8 +64,8 @@ public class ServerIssueRepository {
profiler.stopInfo();
}
- public Iterable<ServerIssue> byComponent(BatchComponent component) {
- return issuesCache.values(component.batchId());
+ public Iterable<ServerIssue> byComponent(InputComponent component) {
+ return issuesCache.values(((DefaultInputComponent) component).batchId());
}
private class SaveIssueConsumer implements Function<ServerIssue, Void> {
@@ -75,7 +76,7 @@ public class ServerIssueRepository {
return null;
}
String componentKey = ComponentKeys.createEffectiveKey(issue.getModuleKey(), issue.hasPath() ? issue.getPath() : null);
- BatchComponent r = resourceCache.get(componentKey);
+ DefaultInputComponent r = (DefaultInputComponent) resourceCache.getByKey(componentKey);
if (r == null) {
// Deleted resource
issuesCache.put(0, issue.getKey(), issue);