use of com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleReport in project synopsys-detect by blackducksoftware.
the class GradleReportParserFunctionalTest method extractCodeLocationTest.
@Test
void extractCodeLocationTest() throws JSONException, IOException {
// Does not work on windows due to path issues.
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
GradleReportParser gradleReportParser = new GradleReportParser();
Optional<GradleReport> gradleReport = gradleReportParser.parseReport(FunctionalTestFiles.asFile("/gradle/dependencyGraph.txt"));
Assertions.assertTrue(gradleReport.isPresent());
GradleReportTransformer transformer = new GradleReportTransformer(EnumListFilter.excludeNone());
CodeLocation codeLocation = transformer.transform(gradleReport.get());
Assertions.assertNotNull(codeLocation);
Assertions.assertEquals("hub-detect", gradleReport.get().getProjectName());
Assertions.assertEquals("2.0.0-SNAPSHOT", gradleReport.get().getProjectVersionName());
String actual = new GsonBuilder().setPrettyPrinting().create().toJson(codeLocation);
JSONAssert.assertEquals(FunctionalTestFiles.asString("/gradle/dependencyGraph-expected.json"), actual, false);
}
use of com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleReport in project synopsys-detect by blackducksoftware.
the class GradleReportParser method parseReport.
public Optional<GradleReport> parseReport(File reportFile) {
GradleReport gradleReport = new GradleReport();
boolean processingMetaData = false;
List<String> configurationLines = new ArrayList<>();
try (InputStream dependenciesInputStream = new FileInputStream(reportFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(dependenciesInputStream, StandardCharsets.UTF_8))) {
while (reader.ready()) {
String line = reader.readLine();
/*
The meta data section will be at the end of the file after all of the "gradle dependencies" output
*/
if (line.startsWith(DETECT_META_DATA_HEADER)) {
processingMetaData = true;
} else if (line.startsWith(DETECT_META_DATA_FOOTER)) {
processingMetaData = false;
} else if (processingMetaData) {
setGradleReportInfo(gradleReport, line);
} else {
if (StringUtils.isBlank(line)) {
parseConfigurationLines(configurationLines, gradleReport);
configurationLines.clear();
} else {
configurationLines.add(line);
}
}
}
parseConfigurationLines(configurationLines, gradleReport);
} catch (Exception e) {
logger.debug(String.format("Failed to read report file: %s", reportFile.getAbsolutePath()), e);
gradleReport = null;
}
return Optional.ofNullable(gradleReport);
}
Aggregations