Search in sources :

Example 11 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class GoVndrExtractor method extract.

public Extraction extract(final File directory, final File vndrConfig) {
    try {
        final VndrParser vndrParser = new VndrParser(externalIdFactory);
        final List<String> venderConfContents = Files.readAllLines(vndrConfig.toPath(), StandardCharsets.UTF_8);
        logger.debug(venderConfContents.stream().collect(Collectors.joining("\n")));
        final DependencyGraph dependencyGraph = vndrParser.parseVendorConf(venderConfContents);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VNDR, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 12 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class MavenCodeLocationPackager method createMavenParseResult.

private MavenParseResult createMavenParseResult(final String sourcePath, final String line, final DependencyGraph graph) {
    final Dependency dependency = textToProject(line);
    if (null != dependency) {
        String codeLocationSourcePath = sourcePath;
        if (!sourcePath.endsWith(dependency.name)) {
            codeLocationSourcePath += "/" + dependency.name;
        }
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.MAVEN, codeLocationSourcePath, dependency.externalId, graph).build();
        return new MavenParseResult(dependency.name, dependency.version, codeLocation);
    }
    return null;
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 13 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class PodlockExtractor method extract.

public Extraction extract(final File directory, final File podlock) {
    String podLockText;
    try {
        logger.trace(String.format("Reading from the pod lock file %s", podlock.getAbsolutePath()));
        podLockText = FileUtils.readFileToString(podlock, StandardCharsets.UTF_8);
        logger.debug(podLockText);
        logger.trace("Finished reading from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    DependencyGraph dependencyGraph;
    try {
        logger.trace("Attempting to create the dependency graph from the pod lock file.");
        dependencyGraph = podlockParser.extractDependencyGraph(podLockText);
        logger.trace("Finished creating the dependency graph from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.COCOAPODS, directory.toString());
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.COCOAPODS, directory.toString(), externalId, dependencyGraph).build();
    return new Extraction.Builder().success(codeLocation).build();
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException)

Example 14 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class RebarParserTest method testParseRebarTreeOutput.

@Test
public void testParseRebarTreeOutput() {
    final MutableMapDependencyGraph expectedGraph = new MutableMapDependencyGraph();
    final Dependency gitInnerParentDependency = buildDependency("git_inner_parent_dependency", "0.0.2");
    final Dependency hexInnerChildDependency = buildDependency("hex_inner_child_dependency", "0.3.0");
    final Dependency hexGrandchildDependency = buildDependency("hex_grandchild_dependency", "4.0.0");
    final Dependency gitInnerChildDependency = buildDependency("git_inner_child_dependency", "0.5.0");
    final Dependency gitGrandchildDependency = buildDependency("git_grandchild_dependency", "6.0.0");
    final Dependency gitOuterParentDependency = buildDependency("git_outer_parent_dependency", "0.0.7");
    final Dependency gitOuterChildDependency = buildDependency("git_outer_child_dependency", "0.8.0");
    expectedGraph.addChildrenToRoot(gitInnerParentDependency, gitOuterParentDependency);
    expectedGraph.addChildWithParent(hexInnerChildDependency, gitInnerParentDependency);
    expectedGraph.addChildWithParents(hexGrandchildDependency, hexInnerChildDependency);
    expectedGraph.addChildWithParent(gitInnerChildDependency, gitInnerParentDependency);
    expectedGraph.addChildWithParents(gitGrandchildDependency, gitInnerChildDependency);
    expectedGraph.addChildWithParents(gitOuterChildDependency, gitOuterParentDependency);
    final DetectCodeLocation codeLocation = build("/hex/dependencyTree.txt");
    final DependencyGraph actualGraph = codeLocation.getDependencyGraph();
    assertGraph(expectedGraph, actualGraph);
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Test(org.junit.Test)

Example 15 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class NugetInspectorPackagerTest method createCodeLocationDWService.

@Test(timeout = 5000L)
public void createCodeLocationDWService() throws IOException {
    final File dependencyNodeFile = new File(getClass().getResource("/nuget/dwCheckApi_inspection_martin.json").getFile());
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final NugetInspectorPackager packager = new NugetInspectorPackager(gson, externalIdFactory);
    final NugetParseResult result = packager.createDetectCodeLocation(dependencyNodeFile);
    for (final DetectCodeLocation codeLocation : result.codeLocations) {
        final BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper();
        final BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper);
        final DependencyGraphTransformer dependencyNodeTransformer = new DependencyGraphTransformer(bdioPropertyHelper, bdioNodeFactory);
        final BdioExternalIdentifier projectId = bdioPropertyHelper.createExternalIdentifier(codeLocation.getExternalId());
        final BdioProject project = bdioNodeFactory.createProject(result.projectName, result.projectVersion, Forge.NUGET.toString(), projectId);
        final Map<ExternalId, BdioNode> components = new HashMap<>();
        components.put(codeLocation.getExternalId(), project);
        final 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) 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) BdioExternalIdentifier(com.synopsys.integration.bdio.model.BdioExternalIdentifier) BdioProject(com.synopsys.integration.bdio.model.BdioProject) BdioNodeFactory(com.synopsys.integration.bdio.BdioNodeFactory) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DependencyGraphTransformer(com.synopsys.integration.bdio.graph.DependencyGraphTransformer) BdioPropertyHelper(com.synopsys.integration.bdio.BdioPropertyHelper) File(java.io.File) Test(org.junit.Test)

Aggregations

DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)44 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)22 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)18 File (java.io.File)17 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)15 ArrayList (java.util.ArrayList)10 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)9 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)9 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)8 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)8 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)7 Test (org.junit.Test)7 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)5 List (java.util.List)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4