]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 12 May 2017 12:53:40 +0000 (14:53 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 12 May 2017 12:53:40 +0000 (14:53 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java

index 7d7eb16271af0dc4adfa723949f7ad64e77d2407..1d659f99c9c55afecc4b02aa36fd78a5f8b3886e 100644 (file)
@@ -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() {
index 8481d88689768a24a30bb4f30936fe22dc8382d6..fbb908584e5a1e433ce1f1b554559b884d7d45f7 100644 (file)
@@ -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) {
index 4aa1f1db48f9fffeccbf5e60bbdd41c720524ee2..acbd3aba5bb4da31f956cea43a872d98b3d6ef96 100644 (file)
  */
 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);
 
 }
index fde5ad8024ceb346c27ea808471d98b3a0cb5308..065dc0bcc4b02f2f266a5a0f66d73566b24870e0 100644 (file)
@@ -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);
       }
     }
   }
index 07674ace5490a1afcaab09ed7c57fc132341207c..be9bfb4476832822b5d94ad20c6fbe18c1c1c06b 100644 (file)
  */
 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));
   }
 }