Search in sources :

Example 1 with GradleReport

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);
}
Also used : GradleReportTransformer(com.synopsys.integration.detectable.detectables.gradle.inspection.parse.GradleReportTransformer) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GradleReportParser(com.synopsys.integration.detectable.detectables.gradle.inspection.parse.GradleReportParser) GsonBuilder(com.google.gson.GsonBuilder) GradleReport(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleReport) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 2 with GradleReport

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) GradleReport(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleReport) FileInputStream(java.io.FileInputStream)

Aggregations

GradleReport (com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleReport)2 GsonBuilder (com.google.gson.GsonBuilder)1 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 GradleReportParser (com.synopsys.integration.detectable.detectables.gradle.inspection.parse.GradleReportParser)1 GradleReportTransformer (com.synopsys.integration.detectable.detectables.gradle.inspection.parse.GradleReportTransformer)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1