Search in sources :

Example 31 with CodeLocation

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

the class NugetInspectorParserTest method createCodeLocationDWService.

@Test
public void createCodeLocationDWService() {
    Assertions.assertTimeout(Duration.ofMillis(5000L), () -> {
        String dependencyNodeFile = FunctionalTestFiles.asString("/nuget/dwCheckApi_inspection_martin.json");
        ExternalIdFactory externalIdFactory = new ExternalIdFactory();
        NugetInspectorParser packager = new NugetInspectorParser(gson, externalIdFactory);
        NugetParseResult result = packager.createCodeLocation(dependencyNodeFile);
        for (CodeLocation codeLocation : result.getCodeLocations()) {
            BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper();
            BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper);
            DependencyGraphTransformer dependencyNodeTransformer = new DependencyGraphTransformer(bdioPropertyHelper, bdioNodeFactory);
            BdioExternalIdentifier projectId = bdioPropertyHelper.createExternalIdentifier(codeLocation.getExternalId().get());
            BdioProject project = bdioNodeFactory.createProject(result.getProjectName(), result.getProjectVersion(), BdioId.createFromPieces(Forge.NUGET.toString()), projectId);
            Map<ExternalId, BdioNode> components = new HashMap<>();
            components.put(codeLocation.getExternalId().get(), project);
            List<BdioComponent> bdioComponents = dependencyNodeTransformer.transformDependencyGraph(codeLocation.getDependencyGraph(), project, codeLocation.getDependencyGraph().getRootDependencies(), components);
            assertEquals(bdioComponents.size(), bdioComponents.size());
        }
    });
}
Also used : BdioNode(com.synopsys.integration.bdio.model.BdioNode) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) HashMap(java.util.HashMap) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioComponent(com.synopsys.integration.bdio.model.BdioComponent) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser) BdioExternalIdentifier(com.synopsys.integration.bdio.model.BdioExternalIdentifier) BdioProject(com.synopsys.integration.bdio.model.BdioProject) BdioNodeFactory(com.synopsys.integration.bdio.BdioNodeFactory) DependencyGraphTransformer(com.synopsys.integration.bdio.graph.DependencyGraphTransformer) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) BdioPropertyHelper(com.synopsys.integration.bdio.BdioPropertyHelper) Test(org.junit.jupiter.api.Test)

Example 32 with CodeLocation

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

the class NugetInspectorParserTest method createCodeLocation.

private void createCodeLocation(String dependencyNodeFile, List<String> expectedOutputFiles) {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    NugetInspectorParser packager = new NugetInspectorParser(gson, externalIdFactory);
    NugetParseResult result = packager.createCodeLocation(dependencyNodeFile);
    for (int i = 0; i < expectedOutputFiles.size(); i++) {
        CodeLocation codeLocation = result.getCodeLocations().get(i);
        String expectedOutputFile = expectedOutputFiles.get(i);
        GraphCompare.assertEqualsResource(expectedOutputFile, codeLocation.getDependencyGraph());
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser)

Example 33 with CodeLocation

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

the class NugetProjectInspectorParseTest method checkParse.

@Test
void checkParse() {
    String inspectorOutput = FunctionalTestFiles.asString("/nuget/project_inspector/ConsoleApp.json");
    List<CodeLocation> codeLocations = new ProjectInspectorParser(new Gson(), new ExternalIdFactory()).parse(inspectorOutput);
    Assertions.assertEquals(2, codeLocations.size());
    Assertions.assertEquals(new File("C:\\Users\\jordanp\\source\\repos\\ConsoleApp3\\ConsoleApp1\\ConsoleApp1.csproj"), codeLocations.get(0).getSourcePath().orElse(null));
    Assertions.assertEquals(new File("C:\\Users\\jordanp\\source\\repos\\ConsoleApp3\\ConsoleApp3\\ConsoleApp3.csproj"), codeLocations.get(1).getSourcePath().orElse(null));
    NameVersionGraphAssert consoleApp1 = new NameVersionGraphAssert(Forge.NUGET, codeLocations.get(0).getDependencyGraph());
    consoleApp1.hasDependency("DocumentFormat.OpenXml", "2.13.0");
    NameVersionGraphAssert consoleApp3 = new NameVersionGraphAssert(Forge.NUGET, codeLocations.get(1).getDependencyGraph());
    consoleApp3.hasDependency("Newtonsoft.Json.Bson", "1.0.2");
    consoleApp3.hasDependency("Serilog", "2.10.0");
    consoleApp3.hasParentChildRelationship("Newtonsoft.Json.Bson", "1.0.2", "Newtonsoft.Json", "12.0.1");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) ProjectInspectorParser(com.synopsys.integration.detectable.detectables.projectinspector.ProjectInspectorParser) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 34 with CodeLocation

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

the class NugetProjectInspectorTest method assertExtraction.

@Override
public void assertExtraction(@NotNull Extraction extraction) {
    List<CodeLocation> codeLocations = extraction.getCodeLocations();
    Assertions.assertEquals(2, codeLocations.size());
    Assertions.assertEquals(new File("C:\\Users\\jordanp\\source\\repos\\ConsoleApp3\\ConsoleApp1\\ConsoleApp1.csproj"), codeLocations.get(0).getSourcePath().orElse(null));
    Assertions.assertEquals(new File("C:\\Users\\jordanp\\source\\repos\\ConsoleApp3\\ConsoleApp3\\ConsoleApp3.csproj"), codeLocations.get(1).getSourcePath().orElse(null));
    NameVersionGraphAssert consoleApp1 = new NameVersionGraphAssert(Forge.NUGET, codeLocations.get(0).getDependencyGraph());
    consoleApp1.hasDependency("DocumentFormat.OpenXml", "2.13.0");
    NameVersionGraphAssert consoleApp3 = new NameVersionGraphAssert(Forge.NUGET, codeLocations.get(1).getDependencyGraph());
    consoleApp3.hasDependency("Newtonsoft.Json.Bson", "1.0.2");
    consoleApp3.hasDependency("Serilog", "2.10.0");
    consoleApp3.hasParentChildRelationship("Newtonsoft.Json.Bson", "1.0.2", "Newtonsoft.Json", "12.0.1");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) File(java.io.File)

Example 35 with CodeLocation

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

the class XcodeWorkspaceDetectableTest method assertExtraction.

@Override
public void assertExtraction(@NotNull Extraction extraction) {
    assertEquals(3, extraction.getCodeLocations().size(), "Expected 1 code location from local and 2 defined in the workspace data file.");
    NameVersionGraphAssert graphAssert;
    CodeLocation workspaceLocalCodeLocation = extraction.getCodeLocations().get(0);
    graphAssert = new NameVersionGraphAssert(Forge.GITHUB, workspaceLocalCodeLocation.getDependencyGraph());
    graphAssert.hasRootDependency("apple/swift-argument-parser", "1.0.1");
    graphAssert.hasNoDependency("invalid/url", "1.2.3");
    graphAssert.hasRootSize(1);
    CodeLocation myLibraryCodeLocation = extraction.getCodeLocations().get(1);
    graphAssert = new NameVersionGraphAssert(Forge.GITHUB, myLibraryCodeLocation.getDependencyGraph());
    graphAssert.hasRootDependency("auth0/Auth0.swift", "1.35.0");
    graphAssert.hasRootSize(1);
    CodeLocation xcodeProjectCodeLocation = extraction.getCodeLocations().get(2);
    graphAssert = new NameVersionGraphAssert(Forge.GITHUB, xcodeProjectCodeLocation.getDependencyGraph());
    graphAssert.hasRootDependency("mac-cain13/R.swift.Library", "5.4.0");
    graphAssert.hasRootSize(1);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)

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