Search in sources :

Example 1 with MutableDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableDependencyGraph 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 2 with MutableDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableDependencyGraph 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 3 with MutableDependencyGraph

use of com.synopsys.integration.bdio.graph.MutableDependencyGraph 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)

Example 4 with MutableDependencyGraph

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

the class GopkgLockParser method parseDepLock.

public DependencyGraph parseDepLock(final String depLockContents) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final GopkgLock gopkgLock = new Toml().read(depLockContents).to(GopkgLock.class);
    for (final Project project : gopkgLock.getProjects()) {
        if (project != null) {
            final NameVersion projectNameVersion = createProjectNameVersion(project);
            project.getPackages().stream().map(packageName -> createDependencyName(projectNameVersion.getName(), packageName)).map(dependencyName -> createGoDependency(dependencyName, projectNameVersion.getVersion())).forEach(graph::addChildToRoot);
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Forge(com.synopsys.integration.bdio.model.Forge) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) Toml(com.moandjiezana.toml.Toml) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) StringUtils(org.apache.commons.lang3.StringUtils) NameVersion(com.synopsys.integration.util.NameVersion) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Toml(com.moandjiezana.toml.Toml)

Example 5 with MutableDependencyGraph

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

the class CondaListParser method parse.

public DependencyGraph parse(final String listJsonText, final String infoJsonText) {
    final Type listType = new TypeToken<ArrayList<CondaListElement>>() {
    }.getType();
    final List<CondaListElement> condaList = gson.fromJson(listJsonText, listType);
    final CondaInfo condaInfo = gson.fromJson(infoJsonText, CondaInfo.class);
    final String platform = condaInfo.platform;
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (final CondaListElement condaListElement : condaList) {
        graph.addChildToRoot(condaListElementToDependency(platform, condaListElement));
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)

Aggregations

MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)19 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)16 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)8 DependencyHistory (com.blackducksoftware.integration.hub.detect.util.DependencyHistory)4 DependencyGraphCombiner (com.synopsys.integration.bdio.graph.DependencyGraphCombiner)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)2 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 NameVersion (com.synopsys.integration.util.NameVersion)2 File (java.io.File)2 Arrays (java.util.Arrays)2