Search in sources :

Example 6 with CodeLocation

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

the class CpanCliExtractor method extract.

public Extraction extract(ExecutableTarget cpanExe, ExecutableTarget cpanmExe, File workingDirectory) throws ExecutableRunnerException {
    toolVersionLogger.log(workingDirectory, cpanExe);
    // TODO: Consider command runner to reduce cognitive load.
    ExecutableOutput cpanListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanExe, "-l"));
    List<String> listText = cpanListOutput.getStandardOutputAsList();
    ExecutableOutput showdepsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanmExe, "--showdeps", "."));
    List<String> showdeps = showdepsOutput.getStandardOutputAsList();
    DependencyGraph dependencyGraph = cpanListParser.parse(listText, showdeps);
    CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
    return new Extraction.Builder().success(detectCodeLocation).build();
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 7 with CodeLocation

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

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

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

Example 10 with CodeLocation

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

the class GoModGraphGenerator method generateGraph.

public CodeLocation generateGraph(GoListModule projectModule, GoRelationshipManager goRelationshipManager, GoModDependencyManager goModDependencyManager) {
    DependencyGraph graph = new BasicDependencyGraph();
    String moduleName = projectModule.getPath();
    if (goRelationshipManager.hasRelationshipsFor(moduleName)) {
        goRelationshipManager.getRelationshipsFor(moduleName).stream().map(relationship -> relationship.getChild().getName()).forEach(childName -> addModuleToGraph(childName, null, graph, goRelationshipManager, goModDependencyManager));
    }
    return new CodeLocation(graph, externalIdFactory.createNameVersionExternalId(Forge.GOLANG, projectModule.getPath(), projectModule.getVersion()));
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

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