Search in sources :

Example 11 with DependencyGraph

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

the class CpanCliExtractor method extract.

public Extraction extract(final File directory, final File cpanExe, final File cpanmExe, ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final ExecutableOutput cpanListOutput = executableRunner.execute(workingDirectory, cpanExe, "-l");
        final List<String> listText = cpanListOutput.getStandardOutputAsList();
        final ExecutableOutput showdepsOutput = executableRunner.execute(workingDirectory, cpanmExe, "--showdeps", ".");
        final List<String> showdeps = showdepsOutput.getStandardOutputAsList();
        final DependencyGraph dependencyGraph = cpanListParser.parse(listText, showdeps);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.CPAN, directory.toString());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CPAN, 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 : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 12 with DependencyGraph

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

the class PackratLockExtractor method extract.

public Extraction extract(final File directory, final File packratlock) {
    try {
        String projectName = "";
        String projectVersion = "";
        if (detectFileFinder.containsAllFiles(directory, "DESCRIPTION")) {
            final File descriptionFile = new File(directory, "DESCRIPTION");
            final List<String> descriptionText = Files.readAllLines(descriptionFile.toPath(), StandardCharsets.UTF_8);
            logger.debug(descriptionText.stream().collect(Collectors.joining("\n")));
            projectName = packratPackager.getProjectName(descriptionText);
            projectVersion = packratPackager.getVersion(descriptionText);
        }
        final List<String> packratLockText = Files.readAllLines(packratlock.toPath(), StandardCharsets.UTF_8);
        final DependencyGraph dependencyGraph = packratPackager.extractProjectDependencies(packratLockText);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.CRAN, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CRAN, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).projectName(projectName).projectVersion(projectVersion).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 13 with DependencyGraph

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

the class GoVndrExtractor method extract.

public Extraction extract(final File directory, final File vndrConfig) {
    try {
        final VndrParser vndrParser = new VndrParser(externalIdFactory);
        final List<String> venderConfContents = Files.readAllLines(vndrConfig.toPath(), StandardCharsets.UTF_8);
        logger.debug(venderConfContents.stream().collect(Collectors.joining("\n")));
        final DependencyGraph dependencyGraph = vndrParser.parseVendorConf(venderConfContents);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VNDR, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 14 with DependencyGraph

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

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

the class PodlockExtractor method extract.

public Extraction extract(final File directory, final File podlock) {
    String podLockText;
    try {
        logger.trace(String.format("Reading from the pod lock file %s", podlock.getAbsolutePath()));
        podLockText = FileUtils.readFileToString(podlock, StandardCharsets.UTF_8);
        logger.debug(podLockText);
        logger.trace("Finished reading from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    DependencyGraph dependencyGraph;
    try {
        logger.trace("Attempting to create the dependency graph from the pod lock file.");
        dependencyGraph = podlockParser.extractDependencyGraph(podLockText);
        logger.trace("Finished creating the dependency graph from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.COCOAPODS, directory.toString());
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.COCOAPODS, directory.toString(), externalId, dependencyGraph).build();
    return new Extraction.Builder().success(codeLocation).build();
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException)

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