Skip to content

Commit

Permalink
Improve utility org.sonar.core.util.Protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Jul 22, 2015
1 parent 5539cff commit c98aca6
Show file tree
Hide file tree
Showing 13 changed files with 992 additions and 240 deletions.
14 changes: 14 additions & 0 deletions compile_protobuf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Usage: compile_protobuf <inputDir> <outputDir>
function compile_protobuf {
echo "Compiling [$1] to [$2]..."
mkdir -p $2
protoc --proto_path=$1 --java_out=$2 $1/*.proto
}

compile_protobuf "sonar-core/src/test/protobuf" "sonar-core/src/test/gen-java"
compile_protobuf "sonar-batch-protocol/src/main/protobuf" "sonar-batch-protocol/src/main/gen-java"



6 changes: 0 additions & 6 deletions sonar-batch-protocol/compile_protobuf.sh

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.io.File;
import javax.annotation.CheckForNull;
import org.sonar.batch.protocol.ProtobufUtil;
import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.Protobuf;

public class BatchReportReader {

Expand All @@ -37,21 +37,21 @@ public BatchReport.Metadata readMetadata() {
if (!fileExists(file)) {
throw new IllegalStateException("Metadata file is missing in analysis report: " + file);
}
return ProtobufUtil.readFile(file, BatchReport.Metadata.PARSER);
return Protobuf.read(file, BatchReport.Metadata.PARSER);
}

public CloseableIterator<BatchReport.ActiveRule> readActiveRules() {
File file = fileStructure.activeRules();
if (!fileExists(file)) {
return CloseableIterator.emptyCloseableIterator();
}
return ProtobufUtil.readStreamFromFile(file, BatchReport.ActiveRule.PARSER);
return Protobuf.readStream(file, BatchReport.ActiveRule.PARSER);
}

public CloseableIterator<BatchReport.Measure> readComponentMeasures(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);
if (fileExists(file)) {
return ProtobufUtil.readStreamFromFile(file, BatchReport.Measure.PARSER);
return Protobuf.readStream(file, BatchReport.Measure.PARSER);
}
return CloseableIterator.emptyCloseableIterator();
}
Expand All @@ -60,7 +60,7 @@ public CloseableIterator<BatchReport.Measure> readComponentMeasures(int componen
public BatchReport.Changesets readChangesets(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, componentRef);
if (fileExists(file)) {
return ProtobufUtil.readFile(file, BatchReport.Changesets.PARSER);
return Protobuf.read(file, BatchReport.Changesets.PARSER);
}
return null;
}
Expand All @@ -70,29 +70,29 @@ public BatchReport.Component readComponent(int componentRef) {
if (!fileExists(file)) {
throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file);
}
return ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
return Protobuf.read(file, BatchReport.Component.PARSER);
}

public CloseableIterator<BatchReport.Issue> readComponentIssues(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);
if (fileExists(file)) {
return ProtobufUtil.readStreamFromFile(file, BatchReport.Issue.PARSER);
return Protobuf.readStream(file, BatchReport.Issue.PARSER);
}
return CloseableIterator.emptyCloseableIterator();
}

public CloseableIterator<BatchReport.Duplication> readComponentDuplications(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef);
if (fileExists(file)) {
return ProtobufUtil.readStreamFromFile(file, BatchReport.Duplication.PARSER);
return Protobuf.readStream(file, BatchReport.Duplication.PARSER);
}
return CloseableIterator.emptyCloseableIterator();
}

public CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef);
if (fileExists(file)) {
return ProtobufUtil.readStreamFromFile(file, BatchReport.Symbol.PARSER);
return Protobuf.readStream(file, BatchReport.Symbol.PARSER);
}
return CloseableIterator.emptyCloseableIterator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.sonar.batch.protocol.output;

import java.io.File;
import org.sonar.batch.protocol.ProtobufUtil;
import org.sonar.core.util.Protobuf;

public class BatchReportWriter {

Expand All @@ -46,72 +46,72 @@ public boolean hasComponentData(FileStructure.Domain domain, int componentRef) {
* Metadata is mandatory
*/
public File writeMetadata(BatchReport.Metadata metadata) {
ProtobufUtil.writeToFile(metadata, fileStructure.metadataFile());
Protobuf.write(metadata, fileStructure.metadataFile());
return fileStructure.metadataFile();
}

public File writeActiveRules(Iterable<BatchReport.ActiveRule> activeRules) {
ProtobufUtil.writeStreamToFile(activeRules, fileStructure.activeRules(), false);
Protobuf.writeStream(activeRules, fileStructure.activeRules(), false);
return fileStructure.metadataFile();
}

public File writeComponent(BatchReport.Component component) {
File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef());
ProtobufUtil.writeToFile(component, file);
Protobuf.write(component, file);
return file;
}

public File writeComponentIssues(int componentRef, Iterable<BatchReport.Issue> issues) {
File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);
ProtobufUtil.writeStreamToFile(issues, file, false);
Protobuf.writeStream(issues, file, false);
return file;
}

public File writeComponentMeasures(int componentRef, Iterable<BatchReport.Measure> measures) {
File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);
ProtobufUtil.writeStreamToFile(measures, file, false);
Protobuf.writeStream(measures, file, false);
return file;
}

public File writeComponentChangesets(BatchReport.Changesets changesets) {
File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, changesets.getComponentRef());
ProtobufUtil.writeToFile(changesets, file);
Protobuf.write(changesets, file);
return file;
}

public File writeComponentDuplications(int componentRef, Iterable<BatchReport.Duplication> duplications) {
File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef);
ProtobufUtil.writeStreamToFile(duplications, file, false);
Protobuf.writeStream(duplications, file, false);
return file;
}

public File writeComponentSymbols(int componentRef, Iterable<BatchReport.Symbol> symbols) {
File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef);
ProtobufUtil.writeStreamToFile(symbols, file, false);
Protobuf.writeStream(symbols, file, false);
return file;
}

public File writeComponentSyntaxHighlighting(int componentRef, Iterable<BatchReport.SyntaxHighlighting> syntaxHighlightingRules) {
File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef);
ProtobufUtil.writeStreamToFile(syntaxHighlightingRules, file, false);
Protobuf.writeStream(syntaxHighlightingRules, file, false);
return file;
}

public File writeComponentCoverage(int componentRef, Iterable<BatchReport.Coverage> coverageList) {
File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, componentRef);
ProtobufUtil.writeStreamToFile(coverageList, file, false);
Protobuf.writeStream(coverageList, file, false);
return file;
}

public File writeTests(int componentRef, Iterable<BatchReport.Test> tests) {
File file = fileStructure.fileFor(FileStructure.Domain.TESTS, componentRef);
ProtobufUtil.writeStreamToFile(tests, file, false);
Protobuf.writeStream(tests, file, false);
return file;
}

public File writeCoverageDetails(int componentRef, Iterable<BatchReport.CoverageDetail> tests) {
File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE_DETAILS, componentRef);
ProtobufUtil.writeStreamToFile(tests, file, false);
Protobuf.writeStream(tests, file, false);
return file;
}

Expand Down

This file was deleted.

Loading

0 comments on commit c98aca6

Please sign in to comment.