Search in sources :

Example 1 with BitbakeGraph

use of com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph in project synopsys-detect by blackducksoftware.

the class BitbakeDependencyGraphTransformerTest method parentHasChild.

@Test
public void parentHasChild() {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    BitbakeGraph bitbakeGraph = new BitbakeGraph();
    bitbakeGraph.addNode("example", "1:75-r50", "meta");
    bitbakeGraph.addNode("foobar", "12", "meta");
    bitbakeGraph.addChild("example", "foobar");
    Map<String, List<String>> recipeToLayerMap = new HashMap<>();
    recipeToLayerMap.put("example", Collections.singletonList("meta"));
    recipeToLayerMap.put("foobar", Collections.singletonList("meta"));
    BitbakeDependencyGraphTransformer bitbakeDependencyGraphTransformer = new BitbakeDependencyGraphTransformer(EnumListFilter.excludeNone());
    DependencyGraph dependencyGraph = bitbakeDependencyGraphTransformer.transform(bitbakeGraph, recipeToLayerMap, null);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.YOCTO, dependencyGraph);
    ExternalId example = graphAssert.hasDependency(externalIdFactory.createYoctoExternalId("meta", "example", "1:75-r50"));
    ExternalId foobar = graphAssert.hasDependency(externalIdFactory.createYoctoExternalId("meta", "foobar", "12"));
    graphAssert.hasParentChildRelationship(example, foobar);
}
Also used : HashMap(java.util.HashMap) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) BitbakeDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) List(java.util.List) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 2 with BitbakeGraph

use of com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph in project synopsys-detect by blackducksoftware.

the class BitbakeDependencyGraphTransformerTest method ignoredNoVersion.

@Test
public void ignoredNoVersion() {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    BitbakeGraph bitbakeGraph = new BitbakeGraph();
    bitbakeGraph.addNode("example", null, "meta");
    Map<String, List<String>> recipeToLayerMap = new HashMap<>();
    recipeToLayerMap.put("example", Collections.singletonList("meta"));
    BitbakeDependencyGraphTransformer bitbakeDependencyGraphTransformer = new BitbakeDependencyGraphTransformer(EnumListFilter.excludeNone());
    DependencyGraph dependencyGraph = bitbakeDependencyGraphTransformer.transform(bitbakeGraph, recipeToLayerMap, null);
    GraphAssert graphAssert = new GraphAssert(Forge.YOCTO, dependencyGraph);
    graphAssert.hasNoDependency(externalIdFactory.createYoctoExternalId("meta", "example", null));
    graphAssert.hasRootSize(0);
}
Also used : HashMap(java.util.HashMap) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) BitbakeDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer) List(java.util.List) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 3 with BitbakeGraph

use of com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph in project synopsys-detect by blackducksoftware.

the class BitbakeGraphTransformerTest method removedQuotesFromName.

@Test
public void removedQuotesFromName() throws IntegrationException {
    HashMap<String, GraphEdge> edges = new HashMap<>();
    HashMap<String, GraphNode> nodes = new HashMap<>();
    addNode("quotes\"removed", "example\\n:example\\n/example/meta/some.bb", nodes);
    Set<String> knownLayers = new HashSet<>(Arrays.asList("aaa", "meta", "bbb"));
    BitbakeGraph bitbakeGraph = buildGraph(nodes, edges, knownLayers);
    assertEquals(1, bitbakeGraph.getNodes().size());
    assertEquals("quotesremoved", bitbakeGraph.getNodes().get(0).getName());
}
Also used : HashMap(java.util.HashMap) GraphNode(com.paypal.digraph.parser.GraphNode) GraphEdge(com.paypal.digraph.parser.GraphEdge) HashSet(java.util.HashSet) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 4 with BitbakeGraph

use of com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph in project synopsys-detect by blackducksoftware.

the class BitbakeGraphTransformerTest method parsedVersionFromLabel.

@Test
public void parsedVersionFromLabel() {
    HashMap<String, GraphEdge> edges = new HashMap<>();
    HashMap<String, GraphNode> nodes = new HashMap<>();
    addNode("name", "name\\n:version\\n/some/meta/path/to.bb", nodes);
    Set<String> knownLayers = new HashSet<>(Arrays.asList("aaa", "meta", "bbb"));
    BitbakeGraph bitbakeGraph = buildGraph(nodes, edges, knownLayers);
    assertEquals(1, bitbakeGraph.getNodes().size());
    assertTrue(bitbakeGraph.getNodes().get(0).getVersion().isPresent());
    assertEquals("version", bitbakeGraph.getNodes().get(0).getVersion().get());
    assertTrue(bitbakeGraph.getNodes().get(0).getLayer().isPresent());
    assertEquals("meta", bitbakeGraph.getNodes().get(0).getLayer().get());
}
Also used : HashMap(java.util.HashMap) GraphNode(com.paypal.digraph.parser.GraphNode) GraphEdge(com.paypal.digraph.parser.GraphEdge) HashSet(java.util.HashSet) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 5 with BitbakeGraph

use of com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph in project synopsys-detect by blackducksoftware.

the class BitbakeExtractor method generateCodeLocationForTargetPackage.

private Optional<CodeLocation> generateCodeLocationForTargetPackage(String targetPackage, File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile, File buildDirectory, ShowRecipesResults showRecipesResults, BitbakeEnvironment bitbakeEnvironment) {
    try {
        BitbakeGraph bitbakeGraph = generateBitbakeGraph(sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, targetPackage, showRecipesResults.getLayerNames());
        Map<String, String> imageRecipes = null;
        if (dependencyTypeFilter.shouldExclude(BitbakeDependencyType.BUILD)) {
            imageRecipes = readImageRecipes(buildDirectory, targetPackage, bitbakeEnvironment);
        }
        DependencyGraph dependencyGraph = bitbakeDependencyGraphTransformer.transform(bitbakeGraph, showRecipesResults.getRecipesWithLayers(), imageRecipes);
        return Optional.of(new CodeLocation(dependencyGraph));
    } catch (ExecutableFailedException | IntegrationException | IOException e) {
        logger.error("Failed to extract a Code Location while running Bitbake against package '{}': {}", targetPackage, e.getMessage());
        logger.debug(e.getMessage(), e);
        return Optional.empty();
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) IntegrationException(com.synopsys.integration.exception.IntegrationException) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)

Aggregations

BitbakeGraph (com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)8 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)6 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6 GraphEdge (com.paypal.digraph.parser.GraphEdge)4 GraphNode (com.paypal.digraph.parser.GraphNode)4 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 BitbakeDependencyGraphTransformer (com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer)3 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)1 GraphAssert (com.synopsys.integration.detectable.util.graph.GraphAssert)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 IOException (java.io.IOException)1