Search in sources :

Example 1 with GraphParser

use of com.paypal.digraph.parser.GraphParser in project hub-detect by blackducksoftware.

the class GraphParserTransformerTest method transform.

@Test
public void transform() throws IOException {
    final GraphParserTransformer graphParserTransformer = new GraphParserTransformer();
    final InputStream inputStream = new ClassPathResource("/bitbake/recipe-depends.dot").getInputStream();
    final GraphParser graphParser = new GraphParser(inputStream);
    final DependencyGraph dependencyGraph = graphParserTransformer.transform(graphParser, "i586-poky-linux");
    assert dependencyGraph.getRootDependencies().size() == 480;
}
Also used : InputStream(java.io.InputStream) GraphParser(com.paypal.digraph.parser.GraphParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with GraphParser

use of com.paypal.digraph.parser.GraphParser in project hub-detect by blackducksoftware.

the class BitbakeExtractor method extract.

public Extraction extract(final ExtractionId extractionId, final File buildEnvScript, final File sourcePath, String[] packageNames, File bash) {
    final File outputDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
    final File bitbakeBuildDirectory = new File(outputDirectory, "build");
    final List<DetectCodeLocation> detectCodeLocations = new ArrayList<>();
    for (final String packageName : packageNames) {
        final File dependsFile = executeBitbakeForRecipeDependsFile(outputDirectory, bitbakeBuildDirectory, buildEnvScript, packageName, bash);
        final String targetArchitecture = executeBitbakeForTargetArchitecture(outputDirectory, buildEnvScript, packageName, bash);
        try {
            if (dependsFile == null) {
                throw new IntegrationException(String.format("Failed to find %s. This may be due to this project being a version of The Yocto Project earlier than 2.3 (Pyro) which is the minimum version for Detect", RECIPE_DEPENDS_FILE_NAME));
            }
            if (StringUtils.isBlank(targetArchitecture)) {
                throw new IntegrationException("Failed to find a target architecture");
            }
            logger.debug(FileUtils.readFileToString(dependsFile, Charset.defaultCharset()));
            final InputStream recipeDependsInputStream = FileUtils.openInputStream(dependsFile);
            final GraphParser graphParser = new GraphParser(recipeDependsInputStream);
            final DependencyGraph dependencyGraph = graphParserTransformer.transform(graphParser, targetArchitecture);
            final ExternalId externalId = new ExternalId(Forge.YOCTO);
            final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.BITBAKE, sourcePath.getCanonicalPath(), externalId, dependencyGraph).build();
            detectCodeLocations.add(detectCodeLocation);
        } catch (final IOException | IntegrationException | NullPointerException e) {
            logger.error(String.format("Failed to extract a Code Location while running Bitbake against package '%s'", packageName));
            logger.debug(e.getMessage(), e);
        }
    }
    final Extraction extraction;
    if (detectCodeLocations.isEmpty()) {
        extraction = new Extraction.Builder().failure("No Code Locations were generated during extraction").build();
    } else {
        extraction = new Extraction.Builder().success(detectCodeLocations).build();
    }
    return extraction;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) InputStream(java.io.InputStream) GraphParser(com.paypal.digraph.parser.GraphParser) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Aggregations

GraphParser (com.paypal.digraph.parser.GraphParser)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 InputStream (java.io.InputStream)2 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)1 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1