diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-05-12 14:53:40 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-05-12 14:53:40 +0200 |
commit | d4b74ece1f2cd2140efd6368a2c0f3e1b715f562 (patch) | |
tree | 5ab9e548a1c42442873c38b72bf6db70f9d5e1b7 | |
parent | c3f190771bfaf1104985bdec74391599956bc66e (diff) | |
download | sonarqube-d4b74ece1f2cd2140efd6368a2c0f3e1b715f562.tar.gz sonarqube-d4b74ece1f2cd2140efd6368a2c0f3e1b715f562.zip |
Fix quality flaws
5 files changed, 28 insertions, 43 deletions
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 7d7eb16271a..1d659f99c9c 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 @@ -19,8 +19,6 @@ */ package org.sonar.scanner.issue.tracking; -import java.util.function.Function; -import javax.annotation.Nullable; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.bootstrap.ProjectDefinition; @@ -61,7 +59,7 @@ public class ServerIssueRepository { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); this.issuesCache = caches.createCache("previousIssues"); caches.registerValueCoder(ServerIssue.class, new ServerIssueValueCoder()); - previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer()); + previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), this::store); profiler.stopInfo(); } @@ -69,27 +67,19 @@ public class ServerIssueRepository { return issuesCache.values(((DefaultInputComponent) component).batchId()); } - private class SaveIssueConsumer implements Function<ServerIssue, Void> { - - @Override - public Void apply(@Nullable ServerIssue issue) { - if (issue == null) { - return null; - } - String moduleKeyWithBranch = issue.getModuleKey(); - ProjectDefinition projectDefinition = reactor.getProjectDefinition(moduleKeyWithBranch); - if (projectDefinition != null) { - String componentKeyWithoutBranch = ComponentKeys.createEffectiveKey(projectDefinition.getKey(), issue.hasPath() ? issue.getPath() : null); - DefaultInputComponent r = (DefaultInputComponent) resourceCache.getByKey(componentKeyWithoutBranch); - if (r != null) { - issuesCache.put(r.batchId(), issue.getKey(), issue); - return null; - } + private void store(ServerIssue issue) { + String moduleKeyWithBranch = issue.getModuleKey(); + ProjectDefinition projectDefinition = reactor.getProjectDefinition(moduleKeyWithBranch); + if (projectDefinition != null) { + String componentKeyWithoutBranch = ComponentKeys.createEffectiveKey(projectDefinition.getKey(), issue.hasPath() ? issue.getPath() : null); + DefaultInputComponent r = (DefaultInputComponent) resourceCache.getByKey(componentKeyWithoutBranch); + if (r != null) { + issuesCache.put(r.batchId(), issue.getKey(), issue); + return; } - // Deleted resource - issuesCache.put(0, issue.getKey(), issue); - return null; } + // Deleted resource + issuesCache.put(0, issue.getKey(), issue); } public Iterable<ServerIssue> issuesOnMissingComponents() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java index 8481d886897..fbb908584e5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java @@ -21,8 +21,7 @@ package org.sonar.scanner.repository; import java.io.IOException; import java.io.InputStream; -import java.util.function.Function; - +import java.util.function.Consumer; import org.apache.commons.io.IOUtils; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; @@ -38,17 +37,17 @@ public class DefaultServerIssuesLoader implements ServerIssuesLoader { } @Override - public void load(String componentKey, Function<ServerIssue, Void> consumer) { + public void load(String componentKey, Consumer<ServerIssue> consumer) { GetRequest getRequest = new GetRequest("/batch/issues.protobuf?key=" + ScannerUtils.encodeForUrl(componentKey)); InputStream is = wsClient.call(getRequest).contentStream(); parseIssues(is, consumer); } - private static void parseIssues(InputStream is, Function<ServerIssue, Void> consumer) { + private static void parseIssues(InputStream is, Consumer<ServerIssue> consumer) { try { ServerIssue previousIssue = ServerIssue.parseDelimitedFrom(is); while (previousIssue != null) { - consumer.apply(previousIssue); + consumer.accept(previousIssue); previousIssue = ServerIssue.parseDelimitedFrom(is); } } catch (IOException e) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java index 4aa1f1db48f..acbd3aba5bb 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java @@ -19,12 +19,11 @@ */ package org.sonar.scanner.repository; -import java.util.function.Function; - +import java.util.function.Consumer; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; public interface ServerIssuesLoader { - void load(String componentKey, Function<ServerIssue, Void> consumer); + void load(String componentKey, Consumer<ServerIssue> consumer); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index fde5ad8024c..065dc0bcc4b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -36,8 +36,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.function.Function; - +import java.util.function.Consumer; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.sonar.api.CoreProperties; @@ -456,9 +455,9 @@ public class ScannerMediumTester { } @Override - public void load(String componentKey, Function<ServerIssue, Void> consumer) { + public void load(String componentKey, Consumer<ServerIssue> consumer) { for (ServerIssue serverIssue : serverIssues) { - consumer.apply(serverIssue); + consumer.accept(serverIssue); } } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java index 07674ace549..be9bfb44768 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java @@ -19,19 +19,18 @@ */ package org.sonar.scanner.repository; -import org.sonar.scanner.WsTestUtil; -import org.sonar.scanner.bootstrap.ScannerWsClient; -import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; -import org.sonar.scanner.repository.DefaultServerIssuesLoader; -import org.junit.Before; -import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import java.util.function.Function; +import java.util.function.Consumer; +import org.junit.Before; +import org.junit.Test; +import org.sonar.scanner.WsTestUtil; +import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -62,7 +61,6 @@ public class DefaultServerIssuesLoaderTest { final List<ServerIssue> result = new ArrayList<>(); loader.load("foo", issue -> { result.add(issue); - return null; }); assertThat(result).extracting("key").containsExactly("ab1", "ab2"); @@ -73,6 +71,6 @@ public class DefaultServerIssuesLoaderTest { InputStream is = mock(InputStream.class); when(is.read()).thenThrow(IOException.class); WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is); - loader.load("foo", mock(Function.class)); + loader.load("foo", mock(Consumer.class)); } } |