diff options
17 files changed, 82 insertions, 48 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/Activity.java b/server/sonar-server/src/main/java/org/sonar/server/activity/Activity.java index f0a50a40c5e..ff9a5a2d145 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/Activity.java +++ b/server/sonar-server/src/main/java/org/sonar/server/activity/Activity.java @@ -19,6 +19,7 @@ */ package org.sonar.server.activity; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.LinkedHashMap; @@ -51,6 +52,7 @@ public class Activity { this.action = action; } + @CheckForNull public String getMessage() { return message; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java index 46e122bae51..c0472856ada 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java @@ -67,7 +67,7 @@ public class ActivityDoc extends BaseDoc { } public String getType() { - return ((String) getField(ActivityIndexDefinition.FIELD_TYPE)); + return (String) getField(ActivityIndexDefinition.FIELD_TYPE); } public void setType(String s) { @@ -83,9 +83,8 @@ public class ActivityDoc extends BaseDoc { 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) { @@ -101,6 +100,7 @@ public class ActivityDoc extends BaseDoc { setField(ActivityIndexDefinition.FIELD_MESSAGE, s); } + @Override public String toString() { return ReflectionToStringBuilder.toString(this); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java index 08c92210404..c9a8c173b23 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java @@ -52,12 +52,10 @@ public class ParseReportStep implements ComputationStep { 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); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActivityQuery.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActivityQuery.java index 5cce6da31fe..fd41cdd86b4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActivityQuery.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActivityQuery.java @@ -42,7 +42,9 @@ public class QProfileActivityQuery extends ActivityQuery { } public QProfileActivityQuery setQprofileKey(@Nullable String qprofileKey) { - addDataOrFilter("profileKey", qprofileKey); + if (qprofileKey != null) { + addDataOrFilter("profileKey", qprofileKey); + } return this; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java index 26682ddb642..adeecf0d06f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java @@ -50,7 +50,7 @@ import org.sonar.api.utils.ZipUtils; 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; @@ -178,7 +178,7 @@ public class ComputationServiceTest { 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") diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java index 1b0d625148a..12dee15de96 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java @@ -24,7 +24,7 @@ import org.junit.Rule; 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; @@ -78,7 +78,7 @@ public class ParseReportStepTest extends BaseStepTest { 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") diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java index 72a319a4e09..a2cee3bd75f 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java @@ -22,8 +22,6 @@ package org.sonar.batch.protocol.output; 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; @@ -44,13 +42,12 @@ public class BatchReportReader { 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) { diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchOutputWriter.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java index ce1ce341d6f..55ced1fa354 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchOutputWriter.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java @@ -23,11 +23,11 @@ import org.sonar.batch.protocol.ProtobufUtil; import java.io.File; -public class BatchOutputWriter { +public class BatchReportWriter { private final FileStructure fileStructure; - public BatchOutputWriter(File dir) { + public BatchReportWriter(File dir) { if (!dir.exists() && !dir.mkdirs()) { throw new IllegalStateException("Unable to create directory: " + dir); } diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java index 8dd814247eb..cee15cf1c65 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java @@ -48,15 +48,48 @@ public class BatchReportReaderTest { 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) diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchOutputWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java index c64d1a0cf07..a26ba76d58d 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchOutputWriterTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java @@ -31,7 +31,7 @@ import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; -public class BatchOutputWriterTest { +public class BatchReportWriterTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -41,7 +41,7 @@ public class BatchOutputWriterTest { File dir = temp.newFolder(); FileUtils.deleteQuietly(dir); - new BatchOutputWriter(dir); + new BatchReportWriter(dir); assertThat(dir).isDirectory().exists(); } @@ -49,7 +49,7 @@ public class BatchOutputWriterTest { @Test public void write_metadata() throws Exception { File dir = temp.newFolder(); - BatchOutputWriter writer = new BatchOutputWriter(dir); + BatchReportWriter writer = new BatchReportWriter(dir); BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder() .setAnalysisDate(15000000L) .setProjectKey("PROJECT_A") @@ -65,7 +65,7 @@ public class BatchOutputWriterTest { @Test public void write_component() throws Exception { File dir = temp.newFolder(); - BatchOutputWriter writer = new BatchOutputWriter(dir); + BatchReportWriter writer = new BatchReportWriter(dir); // no data yet assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse(); @@ -96,7 +96,7 @@ public class BatchOutputWriterTest { @Test public void write_issues() throws Exception { File dir = temp.newFolder(); - BatchOutputWriter writer = new BatchOutputWriter(dir); + BatchReportWriter writer = new BatchReportWriter(dir); // no data yet assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse(); @@ -122,7 +122,7 @@ public class BatchOutputWriterTest { @Test public void write_issues_of_deleted_component() throws Exception { File dir = temp.newFolder(); - BatchOutputWriter writer = new BatchOutputWriter(dir); + BatchReportWriter writer = new BatchReportWriter(dir); // no data yet assertThat(writer.hasComponentData(FileStructure.Domain.ISSUES_ON_DELETED, 1)).isFalse(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java index 7850f6e2db4..d075a9a6300 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java @@ -26,7 +26,7 @@ import org.sonar.api.resources.ResourceUtils; 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; @@ -45,12 +45,12 @@ public class ComponentsPublisher implements ReportPublisher { } @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(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java index fd7bd13b814..0cefc7d25db 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java @@ -30,7 +30,7 @@ import org.sonar.batch.index.BatchResource; 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; @@ -52,7 +52,7 @@ public class IssuesPublisher implements ReportPublisher { } @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(); @@ -71,7 +71,7 @@ public class IssuesPublisher implements ReportPublisher { 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()) @@ -85,7 +85,7 @@ public class IssuesPublisher implements ReportPublisher { 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++; diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/PublishReportJob.java b/sonar-batch/src/main/java/org/sonar/batch/report/PublishReportJob.java index 76713e6a747..3a70259bede 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/PublishReportJob.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/PublishReportJob.java @@ -33,7 +33,7 @@ import org.sonar.api.utils.TempFolder; 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; @@ -84,7 +84,7 @@ public class PublishReportJob implements BatchComponent { 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); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java index 6fe18f50889..07aa03fccbe 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java @@ -19,13 +19,13 @@ */ 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); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java index 30f56d3a46e..5bcc75aa6db 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java @@ -30,7 +30,7 @@ import org.sonar.api.resources.Java; 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; @@ -77,7 +77,7 @@ public class ComponentsPublisherTest { 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(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java index 2674e1ddc78..9a020765298 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java @@ -33,7 +33,7 @@ import org.sonar.api.rule.RuleKey; 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; @@ -98,7 +98,7 @@ public class IssuesPublisherTest { 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); @@ -149,7 +149,7 @@ public class IssuesPublisherTest { 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); diff --git a/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java b/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java index 298b88faef9..81454b05421 100644 --- a/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java +++ b/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java @@ -22,6 +22,8 @@ package org.sonar.core.activity.db; 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 { @@ -65,7 +67,7 @@ public class ActivityDto { return author; } - public ActivityDto setAuthor(String author) { + public ActivityDto setAuthor(@Nullable String author) { this.author = author; return this; } @@ -83,7 +85,7 @@ public class ActivityDto { return message; } - public ActivityDto setMessage(String message) { + public ActivityDto setMessage(@Nullable String message) { this.message = message; return this; } |