Search in sources :

Example 36 with DetectCodeLocation

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

the class GoVendorExtractor method extract.

public Extraction extract(final File directory, final File vendorJsonFile) {
    try {
        final GoVendorJsonParser vendorJsonParser = new GoVendorJsonParser(externalIdFactory);
        final String vendorJsonContents = FileUtils.readFileToString(vendorJsonFile, StandardCharsets.UTF_8);
        logger.debug(vendorJsonContents);
        final DependencyGraph dependencyGraph = vendorJsonParser.parseVendorJson(gson, vendorJsonContents);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VENDOR, 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 37 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation 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)

Example 38 with DetectCodeLocation

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

the class DockerExtractor method findCodeLocations.

private Extraction.Builder findCodeLocations(final File directoryToSearch, final File directory, final String imageName) {
    final File bdioFile = detectFileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
    if (bdioFile != null) {
        SimpleBdioDocument simpleBdioDocument = null;
        try (final InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
            BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
            simpleBdioDocument = bdioReader.readSimpleBdioDocument();
        } catch (final Exception e) {
            return new Extraction.Builder().exception(e);
        }
        if (simpleBdioDocument != null) {
            final DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(simpleBdioDocument.project, simpleBdioDocument.components);
            final String projectName = simpleBdioDocument.project.name;
            final String projectVersionName = simpleBdioDocument.project.version;
            final Forge dockerForge = new Forge(ExternalId.BDIO_ID_SEPARATOR, ExternalId.BDIO_ID_SEPARATOR, simpleBdioDocument.project.bdioExternalIdentifier.forge);
            final String externalIdPath = simpleBdioDocument.project.bdioExternalIdentifier.externalId;
            final ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
            final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.DOCKER, directory.toString(), projectExternalId, dependencyGraph).dockerImage(imageName).build();
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
        }
    }
    return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioReader(com.synopsys.integration.bdio.BdioReader) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 39 with DetectCodeLocation

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

the class AggregateBdioCreator method createAggregateDependencyGraph.

private DependencyGraph createAggregateDependencyGraph(File sourcePath, final List<DetectCodeLocation> codeLocations) {
    final MutableDependencyGraph aggregateDependencyGraph = simpleBdioFactory.createMutableDependencyGraph();
    for (final DetectCodeLocation detectCodeLocation : codeLocations) {
        final Dependency codeLocationDependency = createAggregateDependency(sourcePath, detectCodeLocation);
        aggregateDependencyGraph.addChildrenToRoot(codeLocationDependency);
        aggregateDependencyGraph.addGraphAsChildrenToParent(codeLocationDependency, detectCodeLocation.getDependencyGraph());
    }
    return aggregateDependencyGraph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 40 with DetectCodeLocation

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

the class PackagistParser method getDependencyGraphFromProject.

public PackagistParseResult getDependencyGraphFromProject(final String sourcePath, final String composerJsonText, final String composerLockText) {
    final LazyExternalIdDependencyGraphBuilder builder = new LazyExternalIdDependencyGraphBuilder();
    final JsonObject composerJsonObject = new JsonParser().parse(composerJsonText).getAsJsonObject();
    final NameVersion projectNameVersion = parseNameVersionFromJson(composerJsonObject);
    final JsonObject composerLockObject = new JsonParser().parse(composerLockText).getAsJsonObject();
    final List<PackagistPackage> models = convertJsonToModel(composerLockObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
    final List<NameVersion> rootPackages = parseDependencies(composerJsonObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
    models.forEach(it -> {
        final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, it.getNameVersion().getName(), it.getNameVersion().getVersion());
        final NameDependencyId dependencyId = new NameDependencyId(it.getNameVersion().getName());
        builder.setDependencyInfo(dependencyId, it.getNameVersion().getName(), it.getNameVersion().getVersion(), id);
        if (isRootPackage(it.getNameVersion(), rootPackages)) {
            builder.addChildToRoot(dependencyId);
        }
        it.getDependencies().forEach(child -> {
            if (existsInPackages(child, models)) {
                final NameDependencyId childId = new NameDependencyId(child.getName());
                builder.addChildWithParent(childId, dependencyId);
            } else {
                logger.warn("Dependency was not found in packages list but found a require that used it: " + child.getName());
            }
        });
    });
    ExternalId projectExternalId;
    if (projectNameVersion.getName() == null || projectNameVersion.getVersion() == null) {
        projectExternalId = externalIdFactory.createPathExternalId(Forge.PACKAGIST, sourcePath);
    } else {
        projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, projectNameVersion.getName(), projectNameVersion.getVersion());
    }
    final DependencyGraph graph = builder.build();
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PACKAGIST, sourcePath, projectExternalId, graph).build();
    return new PackagistParseResult(projectNameVersion.getName(), projectNameVersion.getVersion(), codeLocation);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) JsonParser(com.google.gson.JsonParser)

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