Search in sources :

Example 1 with BasicDependencyGraph

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

the class BazelExtractor method generateCodelocation.

@NotNull
private CodeLocation generateCodelocation(Pipelines pipelines, Set<WorkspaceRule> workspaceRules) throws DetectableException, ExecutableFailedException {
    List<Dependency> aggregatedDependencies = new ArrayList<>();
    // Make sure the order of processing deterministic
    List<WorkspaceRule> sortedWorkspaceRules = workspaceRules.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
    for (WorkspaceRule workspaceRule : sortedWorkspaceRules) {
        logger.info("Running processing pipeline for rule {}", workspaceRule);
        List<Dependency> ruleDependencies = pipelines.get(workspaceRule).run();
        logger.info("Number of dependencies discovered for rule {}: {}}", workspaceRule, ruleDependencies.size());
        logger.debug("Dependencies discovered for rule {}: {}}", workspaceRule, ruleDependencies);
        aggregatedDependencies.addAll(ruleDependencies);
    }
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    dependencyGraph.addChildrenToRoot(aggregatedDependencies);
    return new CodeLocation(dependencyGraph);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BasicDependencyGraph

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

the class CondaListParser method parse.

public DependencyGraph parse(String listJsonText, String infoJsonText) {
    Type listType = new TypeToken<ArrayList<CondaListElement>>() {
    }.getType();
    List<CondaListElement> condaList = gson.fromJson(listJsonText, listType);
    CondaInfo condaInfo = gson.fromJson(infoJsonText, CondaInfo.class);
    String platform = condaInfo.platform;
    DependencyGraph graph = new BasicDependencyGraph();
    condaList.stream().map(condaListElement -> dependencyCreator.createFromCondaListElement(condaListElement, platform)).forEach(graph::addChildToRoot);
    return graph;
}
Also used : List(java.util.List) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) TypeToken(com.google.gson.reflect.TypeToken) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) CondaListElement(com.synopsys.integration.detectable.detectables.conda.model.CondaListElement) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) ArrayList(java.util.ArrayList) CondaInfo(com.synopsys.integration.detectable.detectables.conda.model.CondaInfo) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) CondaInfo(com.synopsys.integration.detectable.detectables.conda.model.CondaInfo) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) CondaListElement(com.synopsys.integration.detectable.detectables.conda.model.CondaListElement)

Example 3 with BasicDependencyGraph

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

the class GoModGraphGenerator method generateGraph.

public CodeLocation generateGraph(GoListModule projectModule, GoRelationshipManager goRelationshipManager, GoModDependencyManager goModDependencyManager) {
    DependencyGraph graph = new BasicDependencyGraph();
    String moduleName = projectModule.getPath();
    if (goRelationshipManager.hasRelationshipsFor(moduleName)) {
        goRelationshipManager.getRelationshipsFor(moduleName).stream().map(relationship -> relationship.getChild().getName()).forEach(childName -> addModuleToGraph(childName, null, graph, goRelationshipManager, goModDependencyManager));
    }
    return new CodeLocation(graph, externalIdFactory.createNameVersionExternalId(Forge.GOLANG, projectModule.getPath(), projectModule.getVersion()));
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 4 with BasicDependencyGraph

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

the class IvyParseExtractor method extract.

public Extraction extract(File ivyXmlFile, File buildXmlFile) throws IOException {
    try (InputStream ivyXmlInputStream = new FileInputStream(ivyXmlFile)) {
        IvyDependenciesHandler ivyDependenciesHandler = new IvyDependenciesHandler(externalIdFactory);
        saxParser.parse(ivyXmlInputStream, ivyDependenciesHandler);
        List<Dependency> dependencies = ivyDependenciesHandler.getDependencies();
        DependencyGraph dependencyGraph = new BasicDependencyGraph();
        dependencyGraph.addChildrenToRoot(dependencies);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        Optional<NameVersion> projectName = projectNameParser.parseProjectName(buildXmlFile);
        return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(projectName).build();
    } catch (SAXException e) {
        return new Extraction.Builder().failure(String.format("There was an error parsing file %s: %s", ivyXmlFile.getAbsolutePath(), e.getMessage())).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 5 with BasicDependencyGraph

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

the class MavenCodeLocationPackager method extractCodeLocations.

// mavenOutput should be the full output of mvn dependency:tree (no scope applied); scope filtering is now done by this method
public List<MavenParseResult> extractCodeLocations(String sourcePath, List<String> mavenOutput, List<String> excludedScopes, List<String> includedScopes, List<String> excludedModules, List<String> includedModules) {
    ExcludedIncludedWildcardFilter modulesFilter = ExcludedIncludedWildcardFilter.fromCollections(excludedModules, includedModules);
    ExcludedIncludedWildcardFilter scopeFilter = ExcludedIncludedWildcardFilter.fromCollections(excludedScopes, includedScopes);
    codeLocations = new ArrayList<>();
    currentMavenProject = null;
    dependencyParentStack = new Stack<>();
    parsingProjectSection = false;
    currentGraph = new BasicDependencyGraph();
    level = 0;
    for (String currentLine : mavenOutput) {
        String line = currentLine.trim();
        if (shouldSkipLine(line)) {
            continue;
        }
        line = trimLogLevel(line);
        if (parsingProjectSection && currentMavenProject == null) {
            initializeCurrentMavenProject(modulesFilter, sourcePath, line);
            continue;
        }
        boolean finished = line.contains("--------") || endOfTreePattern.matcher(line).matches();
        if (finished) {
            currentMavenProject = null;
            dependencyParentStack.clear();
            parsingProjectSection = false;
            level = 0;
            continue;
        }
        int previousLevel = level;
        String cleanedLine = calculateCurrentLevelAndCleanLine(line);
        ScopedDependency dependency = textToDependency(cleanedLine);
        if (null == dependency) {
            continue;
        }
        if (currentMavenProject != null) {
            populateGraphDependencies(scopeFilter, dependency, previousLevel);
        }
    }
    addOrphansToGraph(currentGraph, orphans);
    return codeLocations;
}
Also used : ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Aggregations

BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)43 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)38 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)26 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)16 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 List (java.util.List)7 Forge (com.synopsys.integration.bdio.model.Forge)6 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)5 ArrayList (java.util.ArrayList)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 File (java.io.File)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Gson (com.google.gson.Gson)3 NotNull (org.jetbrains.annotations.NotNull)3 GraphEdge (com.paypal.digraph.parser.GraphEdge)2 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)2 DependencyHistory (com.synopsys.integration.detectable.detectable.util.DependencyHistory)2 Extraction (com.synopsys.integration.detectable.extraction.Extraction)2