Search in sources :

Example 66 with CodeLocation

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

the class MavenCliExtractor method extract.

// TODO: Limit 'extractors' to 'execute' and 'read', delegate all other work.
public Extraction extract(File directory, ExecutableTarget mavenExe, MavenCliExtractorOptions mavenCliExtractorOptions) throws ExecutableFailedException {
    toolVersionLogger.log(directory, mavenExe);
    List<String> commandArguments = commandParser.parseCommandString(mavenCliExtractorOptions.getMavenBuildCommand().orElse("")).stream().filter(arg -> !arg.equals("dependency:tree")).collect(Collectors.toList());
    commandArguments.add("dependency:tree");
    // Force maven to use a single thread to ensure the tree output is in the correct order.
    commandArguments.add("-T1");
    ExecutableOutput mvnExecutableResult = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, mavenExe, commandArguments));
    List<String> mavenOutput = mvnExecutableResult.getStandardOutputAsList();
    List<String> excludedScopes = mavenCliExtractorOptions.getMavenExcludedScopes();
    List<String> includedScopes = mavenCliExtractorOptions.getMavenIncludedScopes();
    List<String> excludedModules = mavenCliExtractorOptions.getMavenExcludedModules();
    List<String> includedModules = mavenCliExtractorOptions.getMavenIncludedModules();
    List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mavenOutput, excludedScopes, includedScopes, excludedModules, includedModules);
    List<CodeLocation> codeLocations = Bds.of(mavenResults).map(MavenParseResult::getCodeLocation).toList();
    Optional<MavenParseResult> firstWithName = Bds.of(mavenResults).firstFiltered(it -> StringUtils.isNotBlank(it.getProjectName()));
    Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
    if (firstWithName.isPresent()) {
        builder.projectName(firstWithName.get().getProjectName());
        builder.projectVersion(firstWithName.get().getProjectVersion());
    }
    return builder.build();
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) List(java.util.List) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Bds(com.synopsys.integration.common.util.Bds) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 67 with CodeLocation

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

the class MavenCodeLocationPackager method createMavenParseResult.

private MavenParseResult createMavenParseResult(String sourcePath, String line, DependencyGraph graph) {
    Dependency dependency = textToProject(line);
    if (null != dependency) {
        String codeLocationSourcePath = sourcePath;
        if (!sourcePath.endsWith(dependency.getName())) {
            codeLocationSourcePath += "/" + dependency.getName();
        }
        CodeLocation codeLocation = new CodeLocation(graph, dependency.getExternalId(), new File(codeLocationSourcePath));
        return new MavenParseResult(dependency.getName(), dependency.getVersion(), codeLocation);
    }
    return null;
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File)

Example 68 with CodeLocation

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

the class GoVndrExtractor method extract.

public Extraction extract(File vndrConfig) {
    try {
        VndrParser vndrParser = new VndrParser(externalIdFactory);
        List<String> vendorConfContents = Files.readAllLines(vndrConfig.toPath(), StandardCharsets.UTF_8);
        logger.debug(String.join("\n", vendorConfContents));
        DependencyGraph dependencyGraph = vndrParser.parseVendorConf(vendorConfContents);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(codeLocation).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) VndrParser(com.synopsys.integration.detectable.detectables.go.vendr.parse.VndrParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 69 with CodeLocation

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

the class YarnTransformer method generateCodeLocations.

public List<CodeLocation> generateCodeLocations(YarnLockResult yarnLockResult, List<NameVersion> externalDependencies, @Nullable ExcludedIncludedWildcardFilter workspaceFilter) throws MissingExternalIdException {
    List<CodeLocation> codeLocations = new LinkedList<>();
    logger.debug("Adding root dependencies for project: {}:{}", yarnLockResult.getRootPackageJson().getNameString(), yarnLockResult.getRootPackageJson().getVersionString());
    DependencyGraph rootProjectGraph = buildGraphForProjectOrWorkspace(yarnLockResult, yarnLockResult.getRootPackageJson(), externalDependencies);
    codeLocations.add(new CodeLocation(rootProjectGraph));
    for (YarnWorkspace workspace : yarnLockResult.getWorkspaceData().getWorkspaces()) {
        if ((workspaceFilter == null) || workspaceFilter.shouldInclude(workspace.getWorkspacePackageJson().getDirRelativePath())) {
            logger.debug("Adding root dependencies for workspace: {}", workspace.getWorkspacePackageJson().getDirRelativePath());
            DependencyGraph workspaceGraph = buildGraphForProjectOrWorkspace(yarnLockResult, workspace.getWorkspacePackageJson().getPackageJson(), externalDependencies);
            ExternalId workspaceExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, workspace.getWorkspacePackageJson().getDirRelativePath(), "local");
            codeLocations.add(new CodeLocation(workspaceGraph, workspaceExternalId));
        }
    }
    return codeLocations;
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) YarnWorkspace(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace) LinkedList(java.util.LinkedList)

Example 70 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) throws ExecutableFailedException {
    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();
}
Also used : SwiftPackage(com.synopsys.integration.detectable.detectables.swift.cli.model.SwiftPackage) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)

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