Search in sources :

Example 6 with DependencyGraph

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

the class YarnListParserTest method testThatYarnListLineAtBeginningIsIgnored.

@Test
public void testThatYarnListLineAtBeginningIsIgnored() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("abab@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("yarn list v1.5.1");
    testLines.add("├─ abab@1.0.4");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertNotNull(tempList.get(0));
    assertEquals(1, tempList.size());
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 7 with DependencyGraph

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

the class YarnListParserTest method testThatYarnListWithGrandchildIsParsedCorrectly.

@Test
public void testThatYarnListWithGrandchildIsParsedCorrectly() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("yargs-parser@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    designedYarnLock.add("camelcase@^3.0.0:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("├─ yargs-parser@4.2.1");
    testLines.add("│  └─ camelcase@^3.0.0");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    List<ExternalId> kidsList = new ArrayList<>();
    for (int i = 0; i < tempList.size(); i++) {
        if ("yargs-parser".equals(tempList.get(i).name)) {
            kidsList = new ArrayList<>(dependencyGraph.getChildrenExternalIdsForParent(tempList.get(i)));
        }
    }
    assertListContainsDependency("yargs-parser", "4.2.1", tempList);
    assertListContainsDependency("camelcase", "5.5.2", kidsList);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 8 with DependencyGraph

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

the class YarnListParserTest method testDependencyInYarnListAndNotInLock.

@Test
public void testDependencyInYarnListAndNotInLock() {
    final List<String> designedYarnLock = new ArrayList<>();
    designedYarnLock.add("ajv@5.5.2:");
    designedYarnLock.add("  version \"5.5.2\"");
    designedYarnLock.add("");
    final List<String> testLines = new ArrayList<>();
    testLines.add("yarn list v1.5.1");
    testLines.add("├─ abab@1.0.4");
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final YarnLockParser yarnLockParser = new YarnLockParser();
    final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
    final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
    final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
    assertEquals(1, tempList.size());
    assertListContainsDependency("abab", "1.0.4", tempList);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.Test)

Example 9 with DependencyGraph

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

the class PodlockParser method extractDependencyGraph.

public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
    final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
    final YAMLMapper mapper = new YAMLMapper();
    final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
    final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock);
    for (final Pod pod : podfileLock.pods) {
        logger.trace(String.format("Processing pod %s", pod.name));
        processPod(pod, forgeOverrides, lazyBuilder);
    }
    for (final Pod dependency : podfileLock.dependencies) {
        logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.name));
        final String podText = dependency.name;
        final Optional<DependencyId> dependencyId = parseDependencyId(podText);
        if (dependencyId.isPresent()) {
            lazyBuilder.addChildToRoot(dependencyId.get());
        }
    }
    logger.trace("Attempting to build the dependency graph.");
    final DependencyGraph dependencyGraph = lazyBuilder.build();
    logger.trace("Completed the dependency graph.");
    return dependencyGraph;
}
Also used : DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 10 with DependencyGraph

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

the class CondaCliExtractor method extract.

public Extraction extract(final File directory, final File condaExe, ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final List<String> condaListOptions = new ArrayList<>();
        condaListOptions.add("list");
        final String condaEnvironmentName = detectConfiguration.getProperty(DetectProperty.DETECT_CONDA_ENVIRONMENT_NAME, PropertyAuthority.None);
        if (StringUtils.isNotBlank(condaEnvironmentName)) {
            condaListOptions.add("-n");
            condaListOptions.add(condaEnvironmentName);
        }
        condaListOptions.add("--json");
        final Executable condaListExecutable = new Executable(directory, condaExe, condaListOptions);
        final ExecutableOutput condaListOutput = executableRunner.execute(condaListExecutable);
        final String listJsonText = condaListOutput.getStandardOutput();
        final ExecutableOutput condaInfoOutput = executableRunner.execute(workingDirectory, condaExe, "info", "--json");
        final String infoJsonText = condaInfoOutput.getStandardOutput();
        final DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.ANACONDA, directory.toString());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CONDA, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Aggregations

DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)46 Test (org.junit.Test)26 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)19 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)15 ArrayList (java.util.ArrayList)13 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)12 File (java.io.File)9 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)6 Forge (com.synopsys.integration.bdio.model.Forge)5 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)4 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)4 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)3 LazyExternalIdDependencyGraphBuilder (com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder)3 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)3 NameDependencyId (com.synopsys.integration.bdio.model.dependencyid.NameDependencyId)3 NameVersion (com.synopsys.integration.util.NameVersion)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)2