Search in sources :

Example 61 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class GradleReplacementDetectableTest method assertExtraction.

@Override
public void assertExtraction(@NotNull Extraction extraction) {
    ExtractionUtil.assertSuccessWithCodeLocationCount(extraction, 3);
    CodeLocation root = ExtractionUtil.assertAndGetCodeLocationNamed("root", extraction);
    CodeLocation projectA = ExtractionUtil.assertAndGetCodeLocationNamed("projectA", extraction);
    CodeLocation projectB = ExtractionUtil.assertAndGetCodeLocationNamed("projectB", extraction);
    MavenGraphAssert rootGraph = new MavenGraphAssert(root.getDependencyGraph());
    MavenGraphAssert projectAGraph = new MavenGraphAssert(projectA.getDependencyGraph());
    MavenGraphAssert projectBGraph = new MavenGraphAssert(projectB.getDependencyGraph());
    rootGraph.hasDependency("org.replacement:replaced:3.0.0");
    projectAGraph.hasRootDependency("org.replacement:replaced:2.0.0");
    projectBGraph.hasRootDependency("org.replacement:replaced:1.0.0");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) MavenGraphAssert(com.synopsys.integration.detectable.util.graph.MavenGraphAssert)

Example 62 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 63 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class GradleReportParserFunctionalTest method complexTest.

@Test
void complexTest() {
    Optional<CodeLocation> codeLocation = buildCodeLocation("/gradle/complex_dependencyGraph.txt", true);
    Assertions.assertTrue(codeLocation.isPresent());
    DependencyGraph graph = codeLocation.get().getDependencyGraph();
    MavenGraphAssert graphAssert = new MavenGraphAssert(graph);
    graphAssert.hasDependency("non-project:with-nested:1.0.0");
    graphAssert.hasDependency("solo:component:4.12");
    graphAssert.hasDependency("some.group:child:2.2.2");
    graphAssert.hasDependency("terminal:child:6.2.3");
    // TODO: Get this to work in a sensible way
    // graphAssert.noDependency("child-project");
    // graphAssert.noDependency("nested-parent");
    // graphAssert.noDependency("spring-webflux");
    // graphAssert.noDependency("spring-beans");
    // graphAssert.noDependency("spring-core");
    // graphAssert.noDependency("spring-web");
    // graphAssert.noDependency("should-suppress");
    graphAssert.hasRootDependency("solo:component:4.12");
    graphAssert.hasRootDependency("non-project:with-nested:1.0.0");
    graphAssert.hasRootDependency("some.group:parent:5.0.0");
    graphAssert.hasRootDependency("terminal:child:6.2.3");
    ExternalId parent = graphAssert.hasDependency("some.group:parent:5.0.0");
    ExternalId child = graphAssert.hasDependency("some.group:child:2.2.2");
    graphAssert.hasParentChildRelationship(parent, child);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MavenGraphAssert(com.synopsys.integration.detectable.util.graph.MavenGraphAssert) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 64 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class MavenProjectInspectorTest method assertExtraction.

@Override
public void assertExtraction(@NotNull Extraction extraction) {
    List<CodeLocation> codeLocations = extraction.getCodeLocations();
    Assertions.assertEquals(1, codeLocations.size());
    CodeLocation codeLocation = codeLocations.get(0);
    Set<Dependency> dependencies = codeLocation.getDependencyGraph().getRootDependencies();
    Assertions.assertEquals(1, dependencies.size());
    Dependency first = dependencies.iterator().next();
    Assertions.assertNotNull(first);
    Assertions.assertEquals("COORDINATE_ARTIFACT", first.getName());
    Assertions.assertEquals("COORDINATE_VERSION", first.getVersion());
    ExternalId firstId = first.getExternalId();
    Assertions.assertEquals("COORDINATE_ARTIFACT", firstId.getName());
    Assertions.assertEquals("COORDINATE_VERSION", firstId.getVersion());
    Assertions.assertEquals("COORDINATE_GROUP", firstId.getGroup());
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 65 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class GoVendorExtractor method extract.

public Extraction extract(File vendorJsonFile) {
    try {
        GoVendorJsonParser vendorJsonParser = new GoVendorJsonParser(externalIdFactory);
        String vendorJsonContents = FileUtils.readFileToString(vendorJsonFile, StandardCharsets.UTF_8);
        logger.debug(vendorJsonContents);
        DependencyGraph dependencyGraph = vendorJsonParser.parseVendorJson(gson, vendorJsonContents);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(codeLocation).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GoVendorJsonParser(com.synopsys.integration.detectable.detectables.go.vendor.parse.GoVendorJsonParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10