Search in sources :

Example 1 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class DockerExtractor method findCodeLocations.

private Extraction.Builder findCodeLocations(File directoryToSearch, File directory) {
    File bdioFile = fileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
    if (bdioFile != null) {
        SimpleBdioDocument simpleBdioDocument = null;
        try (InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
            BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
            simpleBdioDocument = bdioReader.readSimpleBdioDocument();
        } catch (Exception e) {
            return new Extraction.Builder().exception(e);
        }
        if (simpleBdioDocument != null) {
            DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
            String projectName = simpleBdioDocument.getProject().name;
            String projectVersionName = simpleBdioDocument.getProject().version;
            // TODO ejk - update this when project external id is not req'd anymore
            Forge dockerForge = new Forge(BdioId.BDIO_ID_SEPARATOR, simpleBdioDocument.getProject().bdioExternalIdentifier.forge);
            String externalIdPath = simpleBdioDocument.getProject().bdioExternalIdentifier.externalId;
            ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
            CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, projectExternalId);
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
        }
    }
    return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString());
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioReader(com.synopsys.integration.bdio.BdioReader) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) Extraction(com.synopsys.integration.detectable.extraction.Extraction) File(java.io.File)

Example 2 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PipenvExtractor method extract.

public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipenvExe, File setupFile, String providedProjectName, String providedProjectVersionName, boolean includeOnlyProjectTree) {
    Extraction extraction;
    try {
        String projectName = resolveProjectName(directory, pythonExe, setupFile, providedProjectName);
        String projectVersionName = resolveProjectVersionName(directory, pythonExe, setupFile, providedProjectVersionName);
        ExecutableOutput pipFreezeOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("run", "pip", "freeze")));
        ExecutableOutput graphOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("graph", "--bare", "--json-tree")));
        PipFreeze pipFreeze = pipenvFreezeParser.parse(pipFreezeOutput.getStandardOutputAsList());
        PipenvGraph pipenvGraph = pipEnvJsonGraphParser.parse(graphOutput.getStandardOutput());
        CodeLocation codeLocation = pipenvTransformer.transform(projectName, projectVersionName, pipFreeze, pipenvGraph, includeOnlyProjectTree);
        return new Extraction.Builder().projectName(projectName).projectVersion(projectVersionName).success(codeLocation).build();
    } catch (Exception e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    return extraction;
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PipenvGraph(com.synopsys.integration.detectable.detectables.pipenv.model.PipenvGraph) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.model.PipFreeze)

Example 3 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class SwiftExtractor method extract.

public Extraction extract(File environmentDirectory, ExecutableTarget swiftExecutable) {
    try {
        toolVersionLogger.log(environmentDirectory, swiftExecutable);
        SwiftPackage rootSwiftPackage = getRootSwiftPackage(environmentDirectory, swiftExecutable);
        CodeLocation codeLocation = swiftPackageTransformer.transform(rootSwiftPackage);
        return new Extraction.Builder().success(codeLocation).projectName(rootSwiftPackage.getName()).projectVersion(rootSwiftPackage.getVersion()).build();
    } catch (IntegrationException | ExecutableRunnerException e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : SwiftPackage(com.synopsys.integration.detectable.detectables.swift.model.SwiftPackage) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) IntegrationException(com.synopsys.integration.exception.IntegrationException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException)

Example 4 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class XcodeSwiftExtractor method extract.

public Extraction extract(File foundPackageResolvedFile, File foundXcodeProjectFile) throws FileNotFoundException {
    FileReader fileReader = new FileReader(foundPackageResolvedFile);
    PackageResolved packageResolved = gson.fromJson(fileReader, PackageResolved.class);
    if (packageResolved == null) {
        // There are no dependencies to extract.
        DependencyGraph dependencyGraph = new MutableMapDependencyGraph();
        CodeLocation emptyCodeLocation = new CodeLocation(dependencyGraph, foundXcodeProjectFile);
        return new Extraction.Builder().success(emptyCodeLocation).build();
    }
    packageResolvedFormatChecker.handleVersionCompatibility(packageResolved, (fileFormatVersion, knownVersions) -> logger.warn(String.format("The format version of Package.resolved (%s) is unknown to Detect, but will attempt to parse anyway. Known format versions are (%s).", fileFormatVersion, StringUtils.join(knownVersions, ", "))));
    DependencyGraph dependencyGraph = packageResolvedTransformer.transform(packageResolved);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    return new Extraction.Builder().success(codeLocation).build();
}
Also used : PackageResolved(com.synopsys.integration.detectable.detectables.xcode.model.PackageResolved) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileReader(java.io.FileReader) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)

Example 5 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10