*/
package org.sonar.server.activity;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.LinkedHashMap;
this.action = action;
}
+ @CheckForNull
public String getMessage() {
return message;
}
}
public String getType() {
- return ((String) getField(ActivityIndexDefinition.FIELD_TYPE));
+ return (String) getField(ActivityIndexDefinition.FIELD_TYPE);
}
public void setType(String s) {
setField(ActivityIndexDefinition.FIELD_ACTION, s);
}
- @CheckForNull
public Map<String, String> getDetails() {
- return this.getNullableField(ActivityIndexDefinition.FIELD_DETAILS);
+ return this.getField(ActivityIndexDefinition.FIELD_DETAILS);
}
public void setDetails(Map<String, String> details) {
setField(ActivityIndexDefinition.FIELD_MESSAGE, s);
}
+ @Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
private void recursivelyProcessComponent(ComputationContext context, int componentRef) {
BatchReportReader reportReader = context.getReportReader();
BatchReport.Component component = reportReader.readComponent(componentRef);
- if (component != null) {
- List<BatchReport.Issue> issues = reportReader.readComponentIssues(componentRef);
- issueComputation.processComponentIssues(context, component.getUuid(), issues);
- for (Integer childRef : component.getChildRefsList()) {
- recursivelyProcessComponent(context, childRef);
- }
+ List<BatchReport.Issue> issues = reportReader.readComponentIssues(componentRef);
+ issueComputation.processComponentIssues(context, component.getUuid(), issues);
+ for (Integer childRef : component.getChildRefsList()) {
+ recursivelyProcessComponent(context, childRef);
}
}
}
public QProfileActivityQuery setQprofileKey(@Nullable String qprofileKey) {
- addDataOrFilter("profileKey", qprofileKey);
+ if (qprofileKey != null) {
+ addDataOrFilter("profileKey", qprofileKey);
+ }
return this;
}
}
import org.sonar.api.utils.internal.JUnitTempFolder;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.computation.db.AnalysisReportDto;
import org.sonar.core.persistence.DbTester;
private File generateZip() throws IOException {
File dir = tempFolder.newDir();
- BatchOutputWriter writer = new BatchOutputWriter(dir);
+ BatchReportWriter writer = new BatchReportWriter(dir);
writer.writeMetadata(BatchReport.Metadata.newBuilder()
.setRootComponentRef(1)
.setProjectKey("PROJECT_KEY")
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.core.component.ComponentDto;
private File generateReport() throws IOException {
File dir = temp.newFolder();
// project and 2 files
- BatchOutputWriter writer = new BatchOutputWriter(dir);
+ BatchReportWriter writer = new BatchReportWriter(dir);
writer.writeMetadata(BatchReport.Metadata.newBuilder()
.setRootComponentRef(1)
.setProjectKey("PROJECT_KEY")
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.protocol.output;
-
-import org.sonar.batch.protocol.ProtobufUtil;
-
-import java.io.File;
-
-public class BatchOutputWriter {
-
- private final FileStructure fileStructure;
-
- public BatchOutputWriter(File dir) {
- if (!dir.exists() && !dir.mkdirs()) {
- throw new IllegalStateException("Unable to create directory: " + dir);
- }
- this.fileStructure = new FileStructure(dir);
- }
-
- FileStructure getFileStructure() {
- return fileStructure;
- }
-
- public boolean hasComponentData(FileStructure.Domain domain, int componentRef) {
- File file = fileStructure.fileFor(domain, componentRef);
- return file.exists() && file.isFile();
- }
-
- /**
- * Metadata is mandatory
- */
- public void writeMetadata(BatchReport.Metadata metadata) {
- ProtobufUtil.writeToFile(metadata, fileStructure.metadataFile());
- }
-
- public void writeComponent(BatchReport.Component component) {
- File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef());
- ProtobufUtil.writeToFile(component, file);
- }
-
- public void writeComponentIssues(int componentRef, Iterable<BatchReport.Issue> issues) {
- BatchReport.Issues.Builder issuesBuilder = BatchReport.Issues.newBuilder();
- issuesBuilder.setComponentRef(componentRef);
- issuesBuilder.addAllList(issues);
- File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);
- ProtobufUtil.writeToFile(issuesBuilder.build(), file);
- }
-
- /**
- * Issues on components which have been deleted are stored in another location.
- * Temporary hack, waiting for computation stack
- */
- public void writeDeletedComponentIssues(int componentRef, String componentUuid, Iterable<BatchReport.Issue> issues) {
- BatchReport.Issues.Builder issuesBuilder = BatchReport.Issues.newBuilder();
- issuesBuilder.setComponentRef(componentRef);
- issuesBuilder.setComponentUuid(componentUuid);
- issuesBuilder.addAllList(issues);
- File file = fileStructure.fileFor(FileStructure.Domain.ISSUES_ON_DELETED, componentRef);
- ProtobufUtil.writeToFile(issuesBuilder.build(), file);
- }
-
-}
import org.sonar.batch.protocol.ProtobufUtil;
import org.sonar.batch.protocol.output.BatchReport.Issues;
-import javax.annotation.CheckForNull;
-
import java.io.File;
import java.util.Collections;
import java.util.List;
return ProtobufUtil.readFile(file, BatchReport.Metadata.PARSER);
}
- @CheckForNull
public BatchReport.Component readComponent(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, componentRef);
- if (file.exists() && file.isFile()) {
- return ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
+ if (!file.exists() || !file.isFile()) {
+ throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file);
}
- return null;
+ return ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
}
public List<BatchReport.Issue> readComponentIssues(int componentRef) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.protocol.output;
+
+import org.sonar.batch.protocol.ProtobufUtil;
+
+import java.io.File;
+
+public class BatchReportWriter {
+
+ private final FileStructure fileStructure;
+
+ public BatchReportWriter(File dir) {
+ if (!dir.exists() && !dir.mkdirs()) {
+ throw new IllegalStateException("Unable to create directory: " + dir);
+ }
+ this.fileStructure = new FileStructure(dir);
+ }
+
+ FileStructure getFileStructure() {
+ return fileStructure;
+ }
+
+ public boolean hasComponentData(FileStructure.Domain domain, int componentRef) {
+ File file = fileStructure.fileFor(domain, componentRef);
+ return file.exists() && file.isFile();
+ }
+
+ /**
+ * Metadata is mandatory
+ */
+ public void writeMetadata(BatchReport.Metadata metadata) {
+ ProtobufUtil.writeToFile(metadata, fileStructure.metadataFile());
+ }
+
+ public void writeComponent(BatchReport.Component component) {
+ File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef());
+ ProtobufUtil.writeToFile(component, file);
+ }
+
+ public void writeComponentIssues(int componentRef, Iterable<BatchReport.Issue> issues) {
+ BatchReport.Issues.Builder issuesBuilder = BatchReport.Issues.newBuilder();
+ issuesBuilder.setComponentRef(componentRef);
+ issuesBuilder.addAllList(issues);
+ File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);
+ ProtobufUtil.writeToFile(issuesBuilder.build(), file);
+ }
+
+ /**
+ * Issues on components which have been deleted are stored in another location.
+ * Temporary hack, waiting for computation stack
+ */
+ public void writeDeletedComponentIssues(int componentRef, String componentUuid, Iterable<BatchReport.Issue> issues) {
+ BatchReport.Issues.Builder issuesBuilder = BatchReport.Issues.newBuilder();
+ issuesBuilder.setComponentRef(componentRef);
+ issuesBuilder.setComponentUuid(componentUuid);
+ issuesBuilder.addAllList(issues);
+ File file = fileStructure.fileFor(FileStructure.Domain.ISSUES_ON_DELETED, componentRef);
+ ProtobufUtil.writeToFile(issuesBuilder.build(), file);
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.protocol.output;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.ProtobufUtil;
-
-import java.io.File;
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class BatchOutputWriterTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void create_dir_if_does_not_exist() throws Exception {
- File dir = temp.newFolder();
- FileUtils.deleteQuietly(dir);
-
- new BatchOutputWriter(dir);
-
- assertThat(dir).isDirectory().exists();
- }
-
- @Test
- public void write_metadata() throws Exception {
- File dir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(dir);
- BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder()
- .setAnalysisDate(15000000L)
- .setProjectKey("PROJECT_A")
- .setRootComponentRef(1);
- writer.writeMetadata(metadata.build());
-
- BatchReport.Metadata read = ProtobufUtil.readFile(writer.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER);
- assertThat(read.getAnalysisDate()).isEqualTo(15000000L);
- assertThat(read.getProjectKey()).isEqualTo("PROJECT_A");
- assertThat(read.getRootComponentRef()).isEqualTo(1);
- }
-
- @Test
- public void write_component() throws Exception {
- File dir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(dir);
-
- // no data yet
- assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse();
-
- // write data
- BatchReport.Component.Builder component = BatchReport.Component.newBuilder()
- .setRef(1)
- .setLanguage("java")
- .setPath("src/Foo.java")
- .setUuid("UUID_A")
- .setType(Constants.ComponentType.FILE)
- .setIsTest(false)
- .addChildRefs(5)
- .addChildRefs(42);
- writer.writeComponent(component.build());
-
- assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
- File file = writer.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1);
- assertThat(file).exists().isFile();
- BatchReport.Component read = ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
- assertThat(read.getRef()).isEqualTo(1);
- assertThat(read.getChildRefsList()).containsOnly(5, 42);
- assertThat(read.hasName()).isFalse();
- assertThat(read.getIsTest()).isFalse();
- assertThat(read.getUuid()).isEqualTo("UUID_A");
- }
-
- @Test
- public void write_issues() throws Exception {
- File dir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(dir);
-
- // no data yet
- assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();
-
- // write data
- BatchReport.Issue issue = BatchReport.Issue.newBuilder()
- .setUuid("ISSUE_A")
- .setLine(50)
- .setMsg("the message")
- .build();
-
- writer.writeComponentIssues(1, Arrays.asList(issue));
-
- assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
- File file = writer.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
- assertThat(file).exists().isFile();
- BatchReport.Issues read = ProtobufUtil.readFile(file, BatchReport.Issues.PARSER);
- assertThat(read.getComponentRef()).isEqualTo(1);
- assertThat(read.hasComponentUuid()).isFalse();
- assertThat(read.getListCount()).isEqualTo(1);
- }
-
- @Test
- public void write_issues_of_deleted_component() throws Exception {
- File dir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(dir);
-
- // no data yet
- assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES_ON_DELETED, 1)).isFalse();
-
- // write data
- BatchReport.Issue issue = BatchReport.Issue.newBuilder()
- .setUuid("ISSUE_A")
- .setLine(50)
- .setMsg("the message")
- .build();
-
- writer.writeDeletedComponentIssues(1, "componentUuid", Arrays.asList(issue));
-
- assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES_ON_DELETED, 1)).isTrue();
- File file = writer.getFileStructure().fileFor(FileStructure.Domain.ISSUES_ON_DELETED, 1);
- assertThat(file).exists().isFile();
- BatchReport.Issues read = ProtobufUtil.readFile(file, BatchReport.Issues.PARSER);
- assertThat(read.getComponentRef()).isEqualTo(1);
- assertThat(read.getComponentUuid()).isEqualTo("componentUuid");
- assertThat(read.getListCount()).isEqualTo(1);
- }
-}
assertThat(reader.readComponentIssues(1)).hasSize(1);
assertThat(reader.readComponentIssues(200)).isEmpty();
assertThat(reader.readComponent(1).getUuid()).isEqualTo("UUID_A");
- assertThat(reader.readComponent(200)).isNull();
Issues deletedComponentIssues = reader.readDeletedComponentIssues(1);
assertThat(deletedComponentIssues.getComponentUuid()).isEqualTo("compUuid");
assertThat(deletedComponentIssues.getListList()).hasSize(1);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void fail_if_missing_metadata_file() throws Exception {
+ File dir = temp.newFolder();
+
+ BatchReportReader reader = new BatchReportReader(dir);
+ reader.readMetadata();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void fail_if_missing_file_on_deleted_component() throws Exception {
+ File dir = temp.newFolder();
+
+ BatchReportReader reader = new BatchReportReader(dir);
+ reader.readDeletedComponentIssues(666);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void fail_if_missing_file_on_component() throws Exception {
+ File dir = temp.newFolder();
+
+ BatchReportReader reader = new BatchReportReader(dir);
+ reader.readComponent(666);
+ }
+ /**
+ * no file if no issues
+ */
+ @Test
+ public void ignore_missing_file_on_component_issues() throws Exception {
+ File dir = temp.newFolder();
+
+ BatchReportReader reader = new BatchReportReader(dir);
+ assertThat(reader.readComponentIssues(666)).isEmpty();
}
private void initFiles(File dir) {
- BatchOutputWriter writer = new BatchOutputWriter(dir);
+ BatchReportWriter writer = new BatchReportWriter(dir);
BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder()
.setAnalysisDate(15000000L)
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.protocol.output;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.batch.protocol.Constants;
+import org.sonar.batch.protocol.ProtobufUtil;
+
+import java.io.File;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BatchReportWriterTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Test
+ public void create_dir_if_does_not_exist() throws Exception {
+ File dir = temp.newFolder();
+ FileUtils.deleteQuietly(dir);
+
+ new BatchReportWriter(dir);
+
+ assertThat(dir).isDirectory().exists();
+ }
+
+ @Test
+ public void write_metadata() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+ BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder()
+ .setAnalysisDate(15000000L)
+ .setProjectKey("PROJECT_A")
+ .setRootComponentRef(1);
+ writer.writeMetadata(metadata.build());
+
+ BatchReport.Metadata read = ProtobufUtil.readFile(writer.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER);
+ assertThat(read.getAnalysisDate()).isEqualTo(15000000L);
+ assertThat(read.getProjectKey()).isEqualTo("PROJECT_A");
+ assertThat(read.getRootComponentRef()).isEqualTo(1);
+ }
+
+ @Test
+ public void write_component() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+
+ // no data yet
+ assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse();
+
+ // write data
+ BatchReport.Component.Builder component = BatchReport.Component.newBuilder()
+ .setRef(1)
+ .setLanguage("java")
+ .setPath("src/Foo.java")
+ .setUuid("UUID_A")
+ .setType(Constants.ComponentType.FILE)
+ .setIsTest(false)
+ .addChildRefs(5)
+ .addChildRefs(42);
+ writer.writeComponent(component.build());
+
+ assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
+ File file = writer.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1);
+ assertThat(file).exists().isFile();
+ BatchReport.Component read = ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
+ assertThat(read.getRef()).isEqualTo(1);
+ assertThat(read.getChildRefsList()).containsOnly(5, 42);
+ assertThat(read.hasName()).isFalse();
+ assertThat(read.getIsTest()).isFalse();
+ assertThat(read.getUuid()).isEqualTo("UUID_A");
+ }
+
+ @Test
+ public void write_issues() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+
+ // no data yet
+ assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();
+
+ // write data
+ BatchReport.Issue issue = BatchReport.Issue.newBuilder()
+ .setUuid("ISSUE_A")
+ .setLine(50)
+ .setMsg("the message")
+ .build();
+
+ writer.writeComponentIssues(1, Arrays.asList(issue));
+
+ assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
+ File file = writer.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
+ assertThat(file).exists().isFile();
+ BatchReport.Issues read = ProtobufUtil.readFile(file, BatchReport.Issues.PARSER);
+ assertThat(read.getComponentRef()).isEqualTo(1);
+ assertThat(read.hasComponentUuid()).isFalse();
+ assertThat(read.getListCount()).isEqualTo(1);
+ }
+
+ @Test
+ public void write_issues_of_deleted_component() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+
+ // no data yet
+ assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES_ON_DELETED, 1)).isFalse();
+
+ // write data
+ BatchReport.Issue issue = BatchReport.Issue.newBuilder()
+ .setUuid("ISSUE_A")
+ .setLine(50)
+ .setMsg("the message")
+ .build();
+
+ writer.writeDeletedComponentIssues(1, "componentUuid", Arrays.asList(issue));
+
+ assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES_ON_DELETED, 1)).isTrue();
+ File file = writer.getFileStructure().fileFor(FileStructure.Domain.ISSUES_ON_DELETED, 1);
+ assertThat(file).exists().isFile();
+ BatchReport.Issues read = ProtobufUtil.readFile(file, BatchReport.Issues.PARSER);
+ assertThat(read.getComponentRef()).isEqualTo(1);
+ assertThat(read.getComponentUuid()).isEqualTo("componentUuid");
+ assertThat(read.getListCount()).isEqualTo(1);
+ }
+}
import org.sonar.batch.index.BatchResource;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.BatchReport;
import javax.annotation.CheckForNull;
}
@Override
- public void publish(BatchOutputWriter writer) {
+ public void publish(BatchReportWriter writer) {
BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch());
recursiveWriteComponent(rootProject, writer);
}
- private void recursiveWriteComponent(BatchResource batchResource, BatchOutputWriter writer) {
+ private void recursiveWriteComponent(BatchResource batchResource, BatchReportWriter writer) {
Resource r = batchResource.resource();
BatchReport.Component.Builder builder = BatchReport.Component.newBuilder();
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.BatchReport;
import javax.annotation.Nullable;
}
@Override
- public void publish(BatchOutputWriter writer) {
+ public void publish(BatchReportWriter writer) {
Collection<Object> deletedComponentKeys = issueCache.componentKeys();
for (BatchResource resource : resourceCache.all()) {
String componentKey = resource.resource().getEffectiveKey();
exportMetadata(writer, count);
}
- private void exportMetadata(BatchOutputWriter writer, int count) {
+ private void exportMetadata(BatchReportWriter writer, int count) {
BatchResource rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch());
BatchReport.Metadata.Builder builder = BatchReport.Metadata.newBuilder()
.setAnalysisDate(((Project) rootProject.resource()).getAnalysisDate().getTime())
writer.writeMetadata(builder.build());
}
- private int exportIssuesOfDeletedComponents(Collection<Object> deletedComponentKeys, BatchOutputWriter writer) {
+ private int exportIssuesOfDeletedComponents(Collection<Object> deletedComponentKeys, BatchReportWriter writer) {
int deletedComponentCount = 0;
for (Object componentKey : deletedComponentKeys) {
deletedComponentCount++;
import org.sonar.api.utils.ZipUtils;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import java.io.File;
import java.io.IOException;
try {
long startTime = System.currentTimeMillis();
File reportDir = temp.newDir("batch-report");
- BatchOutputWriter writer = new BatchOutputWriter(reportDir);
+ BatchReportWriter writer = new BatchReportWriter(reportDir);
for (ReportPublisher publisher : publishers) {
publisher.publish(writer);
}
*/
package org.sonar.batch.report;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
/**
* Adds a sub-part of data to output report
*/
public interface ReportPublisher {
- void publish(BatchOutputWriter writer);
+ void publish(BatchReportWriter writer);
}
import org.sonar.api.resources.Project;
import org.sonar.api.utils.DateUtils;
import org.sonar.batch.index.ResourceCache;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.FileStructure;
import static org.assertj.core.api.Assertions.assertThat;
testFile.setId(6).setUuid("TEST_FILE_UUID");
resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16));
- BatchOutputWriter writer = new BatchOutputWriter(temp.newFolder());
+ BatchReportWriter writer = new BatchReportWriter(temp.newFolder());
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
import org.sonar.api.utils.Duration;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.batch.protocol.output.BatchOutputWriter;
+import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.BatchReport.Metadata;
import org.sonar.batch.protocol.output.BatchReportReader;
when(issueCache.byComponent("foo:src/Foo.php")).thenReturn(Arrays.asList(issue1, issue2));
File outputDir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(outputDir);
+ BatchReportWriter writer = new BatchReportWriter(outputDir);
publisher.publish(writer);
when(issueCache.componentKeys()).thenReturn(Arrays.<Object>asList("foo:deleted.php"));
File outputDir = temp.newFolder();
- BatchOutputWriter writer = new BatchOutputWriter(outputDir);
+ BatchReportWriter writer = new BatchReportWriter(outputDir);
publisher.publish(writer);
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import javax.annotation.Nullable;
+
import java.util.Date;
public class ActivityDto {
return author;
}
- public ActivityDto setAuthor(String author) {
+ public ActivityDto setAuthor(@Nullable String author) {
this.author = author;
return this;
}
return message;
}
- public ActivityDto setMessage(String message) {
+ public ActivityDto setMessage(@Nullable String message) {
this.message = message;
return this;
}