*/
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;
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();
}
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() {
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;
}
@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) {
*/
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);
}
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;
}
@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);
}
}
}
*/
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;
final List<ServerIssue> result = new ArrayList<>();
loader.load("foo", issue -> {
result.add(issue);
- return null;
});
assertThat(result).extracting("key").containsExactly("ab1", "ab2");
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));
}
}