}
}
+ @Test
+ public void read_dependencies() {
+ ScannerReportWriter writer = new ScannerReportWriter(fileStructure);
+ ScannerReport.Dependency dep = ScannerReport.Dependency.newBuilder()
+ .build();
+ writer.appendDependency(dep);
+
+ assertThat(underTest.readDependencies()).toIterable().hasSize(1);
+ }
+
@Test
public void return_null_when_no_file_source() {
assertThat(underTest.readFileSource(UNKNOWN_COMPONENT_REF)).isNull();
return new File(dir, "analysis-warnings.pb");
}
+ public File dependencies() {
+ return new File(dir, "dependencies.pb");
+ }
+
public File root() {
return dir;
}
return Protobuf.readStream(file, ScannerReport.AnalysisWarning.parser());
}
+ public CloseableIterator<ScannerReport.Dependency> readDependencies() {
+ File file = fileStructure.dependencies();
+ if (!fileExists(file)) {
+ return emptyCloseableIterator();
+ }
+ return Protobuf.readStream(file, ScannerReport.Dependency.parser());
+ }
+
private static boolean fileExists(File file) {
return file.exists() && file.isFile();
}
return file;
}
+ public void appendDependency(ScannerReport.Dependency dependency) {
+ File file = fileStructure.dependencies();
+ appendDelimitedTo(file, dependency, "dependency");
+ }
+
public File getSourceFile(int componentRef) {
return fileStructure.fileFor(FileStructure.Domain.SOURCE, componentRef);
}
string software_quality = 1;
string severity = 2;
}
+
+message Dependency {
+ string key = 1;
+ string name = 2;
+ optional string package_manager = 3;
+ optional string full_name = 4;
+ optional string description = 5;
+ optional string version = 6;
+ repeated string parent_dependency_key = 7;
+}
\ No newline at end of file
@Test
void write_adhoc_rule() {
-
- // write data
ScannerReport.AdHocRule rule = ScannerReport.AdHocRule.newBuilder()
.setEngineId("eslint")
.setRuleId("123")
@Test
void write_cve() {
-
- // write data
ScannerReport.Cve cve = ScannerReport.Cve.newBuilder()
.setCveId("CVE-2023-20863")
.setDescription("In spring framework versions prior to 5.2.24 release+ ,5.3.27+ and 6.0.8+ , it is possible for a user to provide a" +
@Test
void write_telemetry() {
-
List<ScannerReport.TelemetryEntry> input = List.of(
ScannerReport.TelemetryEntry.newBuilder()
.setKey("key")
.hasSize(input.size());
}
}
+
+ @Test
+ void write_dependencies() {
+ ScannerReport.Dependency dependency = ScannerReport.Dependency.newBuilder()
+ .setKey("mvn+com.fasterxml.jackson.core:jackson-databind$2.9.7")
+ .setName("jackson-databind")
+ .setFullName("com.fasterxml.jackson.core:jackson-databind")
+ .setDescription("General data-binding functionality for Jackson: works on core streaming API")
+ .setVersion("2.9.7")
+ .addParentDependencyKey("mvn+org.springframework:spring-webmvc$5.1.3.RELEASE")
+ .build();
+ underTest.appendDependency(dependency);
+
+ File file = underTest.getFileStructure().dependencies();
+ assertThat(file).exists().isFile();
+ try (CloseableIterator<ScannerReport.Dependency> read = Protobuf.readStream(file, ScannerReport.Dependency.parser())) {
+ assertThat(Iterators.size(read)).isOne();
+ }
+ }
+
}