aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-08-13 17:44:16 +0200
committerSonarTech <sonartech@sonarsource.com>2018-08-21 20:21:04 +0200
commit2c6a570b99b5813354b0a26ce6110c676d950a84 (patch)
tree3345f959c42520f186c5bb980c36553d25f108d3
parenta48c1dadaf6a81549917bdca8de95706b0941a61 (diff)
downloadsonarqube-2c6a570b99b5813354b0a26ce6110c676d950a84.tar.gz
sonarqube-2c6a570b99b5813354b0a26ce6110c676d950a84.zip
SONAR-8368 use Stream instead of Iterable in Tracking class
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueTrackingDelegator.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchTrackerExecution.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackingResult.java12
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/tracking/AbstractTracker.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java14
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java13
8 files changed, 36 insertions, 47 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java
index 14230afc5b3..738bdf38c8a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.issue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import org.sonar.api.rules.RuleType;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -72,7 +73,7 @@ public class IntegrateIssuesVisitor extends TypeAwareVisitorAdapter {
}
}
- private void fillNewOpenIssues(Component component, Iterable<DefaultIssue> newIssues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
+ private void fillNewOpenIssues(Component component, Stream<DefaultIssue> newIssues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
List<DefaultIssue> list = new ArrayList<>();
newIssues.forEach(issue -> {
@@ -115,13 +116,13 @@ public class IntegrateIssuesVisitor extends TypeAwareVisitorAdapter {
}
}
- private void closeIssues(Component component, Iterable<DefaultIssue> issues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
- for (DefaultIssue issue : issues) {
+ private void closeIssues(Component component, Stream<DefaultIssue> issues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
+ issues.forEach(issue -> {
// TODO should replace flag "beingClosed" by express call to transition "automaticClose"
issue.setBeingClosed(true);
// TODO manual issues -> was updater.setResolution(newIssue, Issue.RESOLUTION_REMOVED, changeContext);. Is it a problem ?
process(component, issue, cacheAppender);
- }
+ });
}
private void process(Component component, DefaultIssue issue, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueTrackingDelegator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueTrackingDelegator.java
index 189d239a39e..f1d07169a2c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueTrackingDelegator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueTrackingDelegator.java
@@ -19,15 +19,14 @@
*/
package org.sonar.ce.task.projectanalysis.issue;
+import java.util.stream.Stream;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.tracking.Tracking;
import org.sonar.db.component.BranchType;
-import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.ce.task.projectanalysis.component.Component;
-import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
public class IssueTrackingDelegator {
@@ -49,7 +48,7 @@ public class IssueTrackingDelegator {
return standardResult(shortBranchTracker.track(component));
} else if (isFirstAnalysisSecondaryLongLivingBranch()) {
Tracking<DefaultIssue, DefaultIssue> tracking = mergeBranchTracker.track(component);
- return new TrackingResult(tracking.getMatchedRaws(), emptyMap(), emptyList(), tracking.getUnmatchedRaws());
+ return new TrackingResult(tracking.getMatchedRaws(), emptyMap(), Stream.empty(), tracking.getUnmatchedRaws());
} else {
return standardResult(tracker.track(component));
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchTrackerExecution.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchTrackerExecution.java
index af321c0de39..6dca1decd57 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchTrackerExecution.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchTrackerExecution.java
@@ -19,15 +19,13 @@
*/
package org.sonar.ce.task.projectanalysis.issue;
-import java.util.ArrayList;
import java.util.List;
-
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.tracking.Input;
import org.sonar.core.issue.tracking.Tracker;
import org.sonar.core.issue.tracking.Tracking;
-import org.sonar.ce.task.projectanalysis.component.Component;
+import org.sonar.core.util.stream.MoreCollectors;
public class ShortBranchTrackerExecution {
private final TrackerBaseInputFactory baseInputFactory;
@@ -49,16 +47,11 @@ public class ShortBranchTrackerExecution {
Input<DefaultIssue> mergeInput = mergeInputFactory.create(component);
Tracking<DefaultIssue, DefaultIssue> mergeTracking = tracker.track(rawInput, mergeInput);
- List<DefaultIssue> unmatchedRaws = toList(mergeTracking.getUnmatchedRaws());
+ List<DefaultIssue> unmatchedRaws = mergeTracking.getUnmatchedRaws().collect(MoreCollectors.toList());
Input<DefaultIssue> unmatchedRawInput = new DefaultTrackingInput(unmatchedRaws, rawInput.getLineHashSequence(), rawInput.getBlockHashSequence());
// do second tracking with base branch using raws issues that are still unmatched
return tracker.track(unmatchedRawInput, baseInput);
}
- private static <T> List<T> toList(Iterable<T> iterable) {
- List<T> list = new ArrayList<>();
- iterable.forEach(list::add);
- return list;
- }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackingResult.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackingResult.java
index 10141e9a186..bb59bf269d5 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackingResult.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackingResult.java
@@ -20,17 +20,17 @@
package org.sonar.ce.task.projectanalysis.issue;
import java.util.Map;
-
+import java.util.stream.Stream;
import org.sonar.core.issue.DefaultIssue;
public class TrackingResult {
private final Map<DefaultIssue, DefaultIssue> issuesToCopy;
private final Map<DefaultIssue, DefaultIssue> issuesToMerge;
- private final Iterable<DefaultIssue> issuesToClose;
- private final Iterable<DefaultIssue> newIssues;
+ private final Stream<DefaultIssue> issuesToClose;
+ private final Stream<DefaultIssue> newIssues;
public TrackingResult(Map<DefaultIssue, DefaultIssue> issuesToCopy, Map<DefaultIssue, DefaultIssue> issuesToMerge,
- Iterable<DefaultIssue> issuesToClose, Iterable<DefaultIssue> newIssues) {
+ Stream<DefaultIssue> issuesToClose, Stream<DefaultIssue> newIssues) {
this.issuesToCopy = issuesToCopy;
this.issuesToMerge = issuesToMerge;
this.issuesToClose = issuesToClose;
@@ -45,11 +45,11 @@ public class TrackingResult {
return issuesToMerge;
}
- public Iterable<DefaultIssue> issuesToClose() {
+ public Stream<DefaultIssue> issuesToClose() {
return issuesToClose;
}
- public Iterable<DefaultIssue> newIssues() {
+ public Stream<DefaultIssue> newIssues() {
return newIssues;
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/AbstractTracker.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AbstractTracker.java
index 3bd47f0881a..e2ca3b97e6e 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/AbstractTracker.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AbstractTracker.java
@@ -40,11 +40,9 @@ public class AbstractTracker<RAW extends Trackable, BASE extends Trackable> {
}
Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create();
- for (BASE base : tracking.getUnmatchedBases()) {
- baseSearch.put(searchKeyFactory.apply(base), base);
- }
+ tracking.getUnmatchedBases().forEach(base -> baseSearch.put(searchKeyFactory.apply(base), base));
- for (RAW raw : tracking.getUnmatchedRaws()) {
+ tracking.getUnmatchedRaws().forEach(raw -> {
SearchKey rawKey = searchKeyFactory.apply(raw);
Collection<BASE> bases = baseSearch.get(rawKey);
bases.stream()
@@ -55,7 +53,7 @@ public class AbstractTracker<RAW extends Trackable, BASE extends Trackable> {
tracking.match(raw, match);
baseSearch.remove(rawKey, match);
});
- }
+ });
}
private int statusRank(BASE i) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java
index feba7b35f12..e80ee3a0d30 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java
@@ -28,6 +28,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
class BlockRecognizer<RAW extends Trackable, BASE extends Trackable> {
@@ -134,14 +135,14 @@ class BlockRecognizer<RAW extends Trackable, BASE extends Trackable> {
}
}
- private static <T extends Trackable> Multimap<Integer, T> groupByLine(Iterable<T> trackables, BlockHashSequence hashSequence) {
+ private static <T extends Trackable> Multimap<Integer, T> groupByLine(Stream<T> trackables, BlockHashSequence hashSequence) {
Multimap<Integer, T> result = LinkedHashMultimap.create();
- for (T trackable : trackables) {
+ trackables.forEach(trackable -> {
Integer line = trackable.getLine();
if (hashSequence.hasLine(line)) {
result.put(line, trackable);
}
- }
+ });
return result;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java
index 3c0e5e37d95..e5f9b9b34e5 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java
@@ -20,11 +20,10 @@
package org.sonar.core.issue.tracking;
import com.google.common.base.MoreObjects;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.Map;
+import java.util.stream.Stream;
import javax.annotation.CheckForNull;
public class Tracking<RAW extends Trackable, BASE extends Trackable> {
@@ -38,9 +37,6 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> {
private final Collection<RAW> raws;
private final Collection<BASE> bases;
- private final Predicate<RAW> unmatchedRawPredicate = raw -> !rawToBase.containsKey(raw);
- private final Predicate<BASE> unmatchedBasePredicate = raw -> !baseToRaw.containsKey(raw);
-
public Tracking(Collection<RAW> rawInput, Collection<BASE> baseInput) {
this.raws = rawInput;
this.bases = baseInput;
@@ -51,8 +47,8 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> {
* that the traversal does not fail if method {@link #match(Trackable, Trackable)}
* is called.
*/
- public Iterable<RAW> getUnmatchedRaws() {
- return Iterables.filter(raws, unmatchedRawPredicate);
+ public Stream<RAW> getUnmatchedRaws() {
+ return raws.stream().filter(raw -> !rawToBase.containsKey(raw));
}
public Map<RAW, BASE> getMatchedRaws() {
@@ -67,8 +63,8 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> {
/**
* The base issues that are not matched by a raw issue and that need to be closed.
*/
- public Iterable<BASE> getUnmatchedBases() {
- return Iterables.filter(bases, unmatchedBasePredicate);
+ public Stream<BASE> getUnmatchedBases() {
+ return bases.stream().filter(base -> !baseToRaw.containsKey(base));
}
boolean containsUnmatchedBase(BASE base) {
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 ebff1468f42..1e2913c8d08 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
@@ -28,6 +28,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.batch.ScannerSide;
@@ -205,20 +206,20 @@ public class LocalIssueTracking {
}
}
- private void addUnmatchedFromServer(Iterable<ServerIssueFromWs> unmatchedIssues, Collection<TrackedIssue> mergeTo, String componentKey) {
- for (ServerIssueFromWs unmatchedIssue : unmatchedIssues) {
+ private void addUnmatchedFromServer(Stream<ServerIssueFromWs> unmatchedIssues, Collection<TrackedIssue> mergeTo, String componentKey) {
+ unmatchedIssues.forEach(unmatchedIssue -> {
org.sonar.scanner.protocol.input.ScannerInput.ServerIssue unmatchedPreviousIssue = unmatchedIssue.getDto();
TrackedIssue unmatched = IssueTransformer.toTrackedIssue(unmatchedPreviousIssue, componentKey);
updateUnmatchedIssue(unmatched);
mergeTo.add(unmatched);
- }
+ });
}
- private static void addUnmatchedFromReport(Iterable<TrackedIssue> rawIssues, Collection<TrackedIssue> trackedIssues, Date analysisDate) {
- for (TrackedIssue rawIssue : rawIssues) {
+ private static void addUnmatchedFromReport(Stream<TrackedIssue> rawIssues, Collection<TrackedIssue> trackedIssues, Date analysisDate) {
+ rawIssues.forEach(rawIssue -> {
rawIssue.setCreationDate(analysisDate);
trackedIssues.add(rawIssue);
- }
+ });
}
private void addIssuesOnDeletedComponents(Collection<TrackedIssue> issues, String componentKey) {