aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java32
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java2
3 files changed, 20 insertions, 20 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
index 3bd9d5a6928..3d2a23d99a0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
@@ -19,19 +19,19 @@
*/
package org.sonar.api.utils.log;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import java.util.ArrayList;
+import com.google.common.collect.ImmutableList;
+import java.util.Collections;
import java.util.List;
-import java.util.Optional;
-import java.util.function.Predicate;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
public class ListInterceptor implements LogInterceptor {
- private final List<LogAndArguments> logs = new ArrayList<>();
- private final ListMultimap<LoggerLevel, LogAndArguments> logsByLevel = ArrayListMultimap.create();
+ private final List<LogAndArguments> logs = new CopyOnWriteArrayList<>();
+ private final Map<LoggerLevel, List<LogAndArguments>> logsByLevel = new ConcurrentHashMap<>();
@Override
public void log(LoggerLevel level, String msg) {
@@ -68,19 +68,25 @@ public class ListInterceptor implements LogInterceptor {
private void add(LoggerLevel level, LogAndArguments l) {
logs.add(l);
- logsByLevel.put(level, l);
+ logsByLevel.compute(level, (key, existingList) -> {
+ if (existingList == null) {
+ return new CopyOnWriteArrayList<>(new LogAndArguments[] {l});
+ }
+ existingList.add(l);
+ return existingList;
+ });
}
public List<String> logs() {
return logs.stream().map(LogAndArguments::getFormattedMsg).collect(Collectors.toList());
}
- public Optional<String> findFirst(Predicate<String> logPredicate) {
- return logs.stream().map(LogAndArguments::getFormattedMsg).filter(logPredicate).findFirst();
- }
-
public List<String> logs(LoggerLevel level) {
- return logsByLevel.get(level).stream().map(LogAndArguments::getFormattedMsg).collect(Collectors.toList());
+ List<LogAndArguments> res = logsByLevel.get(level);
+ if (res == null) {
+ return Collections.emptyList();
+ }
+ return ImmutableList.copyOf(res).stream().map(LogAndArguments::getFormattedMsg).collect(Collectors.toList());
}
public List<LogAndArguments> getLogs() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java
index a58bbe8f30c..2b7ddc8e9ac 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogTester.java
@@ -20,8 +20,6 @@
package org.sonar.api.utils.log;
import java.util.List;
-import java.util.Optional;
-import java.util.function.Predicate;
import org.junit.rules.ExternalResource;
/**
@@ -92,10 +90,6 @@ public class LogTester extends ExternalResource {
return ((ListInterceptor) LogInterceptors.get()).logs();
}
- public Optional<String> findFirstLog(Predicate<String> msgPredicate) {
- return ((ListInterceptor) LogInterceptors.get()).findFirst(msgPredicate);
- }
-
/**
* Logs in chronological order (item at index 0 is the oldest one) for
* a given level
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
index 6c536b0e527..32a9811f5b9 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
@@ -60,7 +60,7 @@ public class ProgressReportTest {
underTest.message("Some message");
boolean logged = false;
while (!logged) {
- logged = logTester.findFirstLog("Some message"::equals).isPresent();
+ logged = logTester.logs().contains("Some message");
}
underTest.stop("stop");
}