Search in sources :

Example 1 with MutableMapDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.

the class PearParser method parsePearDependencyList.

public DependencyGraph parsePearDependencyList(final ExecutableOutput pearListing, final ExecutableOutput pearDependencies) {
    DependencyGraph graph = new MutableMapDependencyGraph();
    if (StringUtils.isNotBlank(pearDependencies.getErrorOutput()) || StringUtils.isNotBlank(pearListing.getErrorOutput())) {
        logger.error("There was an error during execution.");
        if (StringUtils.isNotBlank(pearListing.getErrorOutput())) {
            logger.error("Pear list error: ");
            logger.error(pearListing.getErrorOutput());
        }
        if (StringUtils.isNotBlank(pearDependencies.getErrorOutput())) {
            logger.error("Pear package-dependencies error: ");
            logger.error(pearDependencies.getErrorOutput());
        }
    } else if (!(pearDependencies.getStandardOutputAsList().size() > 0) || !(pearListing.getStandardOutputAsList().size() > 0)) {
        logger.error("No information retrieved from running pear commands");
    } else {
        final List<String> nameList = findDependencyNames(pearDependencies.getStandardOutputAsList());
        graph = createPearDependencyGraphFromList(pearListing.getStandardOutputAsList(), nameList);
    }
    return graph;
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with MutableMapDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.

the class PipenvGraphParser method parse.

public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) {
    final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
    final Stack<Dependency> dependencyStack = new Stack<>();
    final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream().map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2).collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine));
    int lastLevel = -1;
    for (final String line : pipenvGraphOutput) {
        final int currentLevel = getLevel(line);
        final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line);
        if (!parsedDependency.isPresent()) {
            continue;
        }
        final Dependency dependency = parsedDependency.get();
        if (currentLevel == lastLevel) {
            dependencyStack.pop();
        } else {
            for (; lastLevel >= currentLevel; lastLevel--) {
                dependencyStack.pop();
            }
        }
        if (dependencyStack.size() > 0) {
            dependencyGraph.addChildWithParent(dependency, dependencyStack.peek());
        } else {
            dependencyGraph.addChildrenToRoot(dependency);
        }
        lastLevel = currentLevel;
        dependencyStack.push(dependency);
    }
    if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) {
        final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build();
        return new PipParseResult(projectName, projectVersionName, codeLocation);
    } else {
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Stack(java.util.Stack) List(java.util.List) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Map(java.util.Map) DetectCodeLocationType(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocationType) Optional(java.util.Optional) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Stack(java.util.Stack) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)

Example 3 with MutableMapDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.

the class PipInspectorTreeParser method parse.

public Optional<PipParseResult> parse(final List<String> pipInspectorOutputAsList, final String sourcePath) {
    PipParseResult parseResult = null;
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final DependencyHistory history = new DependencyHistory();
    Dependency project = null;
    for (final String line : pipInspectorOutputAsList) {
        final String trimmedLine = StringUtils.trimToEmpty(line);
        if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
            parseErrorsFromLine(trimmedLine);
            continue;
        }
        final Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
        final int lineLevel = getLineLevel(trimmedLine);
        try {
            history.clearDependenciesDeeperThan(lineLevel);
        } catch (final IllegalStateException e) {
            logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
        }
        if (project == null) {
            project = currentDependency;
        } else if (project.equals(history.getLastDependency())) {
            graph.addChildToRoot(currentDependency);
        } else if (history.isEmpty()) {
            graph.addChildToRoot(currentDependency);
        } else {
            graph.addChildWithParents(currentDependency, history.getLastDependency());
        }
        history.add(currentDependency);
    }
    if (project != null) {
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, project.externalId, graph).build();
        parseResult = new PipParseResult(project.name, project.version, codeLocation);
    }
    return Optional.ofNullable(parseResult);
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyHistory(com.blackducksoftware.integration.hub.detect.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 4 with MutableMapDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.

the class BdioCodeLocationCreator method transformDetectCodeLocationsIntoBdioCodeLocations.

private List<BdioCodeLocation> transformDetectCodeLocationsIntoBdioCodeLocations(final List<DetectCodeLocation> codeLocations, final String codeLocationName, final boolean combineCodeLocations) {
    final List<BdioCodeLocation> bdioCodeLocations;
    final IntegrationEscapeUtil integrationEscapeUtil = new IntegrationEscapeUtil();
    if (codeLocations.size() > 1) {
        // we must either combine or create a unique name.
        if (combineCodeLocations) {
            final DependencyGraphCombiner combiner = new DependencyGraphCombiner();
            logger.info("Combining duplicate code locations with name: " + codeLocationName);
            final MutableDependencyGraph combinedGraph = new MutableMapDependencyGraph();
            final DetectCodeLocation finalCodeLocation = copyCodeLocation(codeLocations.get(0), combinedGraph);
            codeLocations.stream().filter(codeLocation -> shouldCombine(logger, finalCodeLocation, codeLocation)).forEach(codeLocation -> combiner.addGraphAsChildrenToRoot(combinedGraph, codeLocation.getDependencyGraph()));
            final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(finalCodeLocation, codeLocationName, createBdioName(codeLocationName, integrationEscapeUtil));
            bdioCodeLocations = Arrays.asList(bdioCodeLocation);
        } else {
            bdioCodeLocations = new ArrayList<>();
            for (int i = 0; i < codeLocations.size(); i++) {
                final DetectCodeLocation codeLocation = codeLocations.get(i);
                final String newCodeLocationName = String.format("%s %s", codeLocationName, Integer.toString(i));
                final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(codeLocation, newCodeLocationName, createBdioName(newCodeLocationName, integrationEscapeUtil));
                bdioCodeLocations.add(bdioCodeLocation);
            }
        }
    } else if (codeLocations.size() == 1) {
        final DetectCodeLocation codeLocation = codeLocations.get(0);
        final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(codeLocation, codeLocationName, createBdioName(codeLocationName, integrationEscapeUtil));
        bdioCodeLocations = Arrays.asList(bdioCodeLocation);
    } else {
        logger.error("Created a code location name but no code locations.");
        bdioCodeLocations = new ArrayList<>();
    }
    return bdioCodeLocations;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) Arrays(java.util.Arrays) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NameVersion(com.synopsys.integration.util.NameVersion) Event(com.blackducksoftware.integration.hub.detect.workflow.event.Event) PropertyAuthority(com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority) Map(java.util.Map) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) IntegrationEscapeUtil(com.synopsys.integration.util.IntegrationEscapeUtil) DetectProperty(com.blackducksoftware.integration.hub.detect.configuration.DetectProperty) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) DetectEnumUtil(com.blackducksoftware.integration.hub.detect.util.DetectEnumUtil) Set(java.util.Set) EventSystem(com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem) Collectors(java.util.stream.Collectors) File(java.io.File) DependencyGraphCombiner(com.synopsys.integration.bdio.graph.DependencyGraphCombiner) List(java.util.List) Optional(java.util.Optional) IntegrationEscapeUtil(com.synopsys.integration.util.IntegrationEscapeUtil) ArrayList(java.util.ArrayList) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyGraphCombiner(com.synopsys.integration.bdio.graph.DependencyGraphCombiner)

Example 5 with MutableMapDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.

the class GoVendorJsonParser method parseVendorJson.

public DependencyGraph parseVendorJson(final Gson gson, final String vendorJsonContents) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    GoVendorJsonData vendorJsonData = gson.fromJson(vendorJsonContents, GoVendorJsonData.class);
    logger.trace(String.format("vendorJsonData: %s", vendorJsonData));
    for (GoVendorJsonPackageData pkg : vendorJsonData.getPackages()) {
        if (StringUtils.isNotBlank(pkg.getPath()) && StringUtils.isNotBlank(pkg.getRevision())) {
            final ExternalId dependencyExternalId = externalIdFactory.createNameVersionExternalId(Forge.GOLANG, pkg.getPath(), pkg.getRevision());
            final Dependency dependency = new Dependency(pkg.getPath(), pkg.getRevision(), dependencyExternalId);
            logger.trace(String.format("dependency: %s", dependency.externalId.toString()));
            graph.addChildToRoot(dependency);
        } else {
            logger.debug(String.format("Omitting package path:'%s', revision:'%s' (one or both of path, revision is/are missing)", pkg.getPath(), pkg.getRevision()));
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Aggregations

MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)21 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)17 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)12 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)11 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)8 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 DependencyHistory (com.blackducksoftware.integration.hub.detect.util.DependencyHistory)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 DependencyGraphCombiner (com.synopsys.integration.bdio.graph.DependencyGraphCombiner)2 Forge (com.synopsys.integration.bdio.model.Forge)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 NameVersion (com.synopsys.integration.util.NameVersion)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2