Search in sources :

Example 1 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction 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 2 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction 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 3 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PackratLockExtractor method extract.

public Extraction extract(File directory, File packratlock) {
    try {
        NameVersion nameVersion = determineProjectNameVersion(directory);
        List<String> packratLockText = Files.readAllLines(packratlock.toPath(), StandardCharsets.UTF_8);
        DependencyGraph dependencyGraph = packRatLockFileParser.parseProjectDependencies(packratLockText);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(codeLocation).projectName(nameVersion.getName()).projectVersion(nameVersion.getVersion()).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException)

Example 4 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class GradleInspectorExtractor method extract.

public Extraction extract(File directory, ExecutableTarget gradleExe, @Nullable String gradleCommand, ProxyInfo proxyInfo, File gradleInspector, File outputDirectory) throws ExecutableFailedException {
    try {
        toolVersionLogger.log(directory, gradleExe);
        gradleRunner.runGradleDependencies(directory, gradleExe, gradleInspector, gradleCommand, proxyInfo, outputDirectory);
        File rootProjectMetadataFile = fileFinder.findFile(outputDirectory, "rootProjectMetadata.txt");
        List<File> reportFiles = fileFinder.findFiles(outputDirectory, "*_dependencyGraph.txt");
        List<CodeLocation> codeLocations = new ArrayList<>();
        reportFiles.stream().map(gradleReportParser::parseReport).filter(Optional::isPresent).map(Optional::get).map(gradleReportTransformer::transform).forEach(codeLocations::add);
        Optional<NameVersion> projectNameVersion = Optional.empty();
        if (rootProjectMetadataFile != null) {
            projectNameVersion = parseRootProjectMetadataFile(rootProjectMetadataFile);
        } else {
            logger.warn("Gradle inspector did not create a meta data report so no project version information was found.");
        }
        return new Extraction.Builder().success(codeLocations).nameVersionIfPresent(projectNameVersion).build();
    } catch (IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) File(java.io.File)

Example 5 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PubSpecExtractor method extract.

public Extraction extract(File pubSpecLockFile, @Nullable File pubSpecYamlFile) throws IOException {
    List<String> pubSpecLockLines = Files.readAllLines(pubSpecLockFile.toPath(), StandardCharsets.UTF_8);
    Optional<NameVersion> nameVersion = Optional.empty();
    if (pubSpecYamlFile != null) {
        List<String> pubSpecYamlLines = Files.readAllLines(pubSpecYamlFile.toPath(), StandardCharsets.UTF_8);
        nameVersion = nameVersionParser.parseNameVersion(pubSpecYamlLines);
    }
    DependencyGraph dependencyGraph = pubSpecLockParser.parse(pubSpecLockLines);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(nameVersion).build();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Aggregations

Extraction (com.synopsys.integration.detectable.extraction.Extraction)63 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)38 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)23 IOException (java.io.IOException)19 Test (org.junit.jupiter.api.Test)18 File (java.io.File)17 ArrayList (java.util.ArrayList)14 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)13 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)12 NameVersion (com.synopsys.integration.util.NameVersion)12 Executable (com.synopsys.integration.executable.Executable)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)9 List (java.util.List)9 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)7 Collectors (java.util.stream.Collectors)7 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)6 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6