Search in sources :

Example 16 with CodeLocation

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

the class LernaPackager method generateLernaResult.

public LernaResult generateLernaResult(File sourceDirectory, File rootPackageJson, List<LernaPackage> lernaPackages) {
    LernaLockFileResult rootLockFile = findLockFiles(sourceDirectory);
    LernaResult rootLernaResult = parse(sourceDirectory, rootPackageJson, rootLockFile, new ArrayList<>());
    List<NameVersion> externalPackages = lernaPackages.stream().map(lernaPackage -> new NameVersion(lernaPackage.getName(), lernaPackage.getVersion())).collect(Collectors.toList());
    List<CodeLocation> codeLocations = new ArrayList<>(rootLernaResult.getCodeLocations());
    for (LernaPackage lernaPackage : lernaPackages) {
        LernaResult lernaResult = extractPackage(lernaPackage, externalPackages, rootLockFile);
        if (lernaResult != null) {
            if (lernaResult.isSuccess()) {
                lernaResult.getCodeLocations().stream().map(codeLocation -> new CodeLocation(codeLocation.getDependencyGraph(), codeLocation.getExternalId().orElse(null), new File(lernaPackage.getLocation()))).forEach(codeLocations::add);
            } else if (lernaResult.isFailure()) {
                String extractionErrorMessage = lernaResult.getException().map(Throwable::getMessage).orElse("Error message not found.");
                logger.warn("Failed to extract lerna package: {}", extractionErrorMessage);
                lernaResult.getException().ifPresent(exception -> logger.debug("Lerna Extraction Failure", exception));
            }
        }
    }
    return LernaResult.success(rootLernaResult.getProjectName(), rootLernaResult.getProjectVersionName(), codeLocations);
}
Also used : NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) LoggerFactory(org.slf4j.LoggerFactory) YarnResult(com.synopsys.integration.detectable.detectables.yarn.YarnResult) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) LernaResult(com.synopsys.integration.detectable.detectables.lerna.model.LernaResult) YarnPackager(com.synopsys.integration.detectable.detectables.yarn.YarnPackager) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult) NpmLockfilePackager(com.synopsys.integration.detectable.detectables.npm.lockfile.parse.NpmLockfilePackager) Logger(org.slf4j.Logger) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) PackageJsonReader(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Nullable(org.jetbrains.annotations.Nullable) YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Collections(java.util.Collections) LernaLockFileResult(com.synopsys.integration.detectable.detectables.lerna.lockfile.LernaLockFileResult) LernaResult(com.synopsys.integration.detectable.detectables.lerna.model.LernaResult) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) LernaLockFileResult(com.synopsys.integration.detectable.detectables.lerna.lockfile.LernaLockFileResult) ArrayList(java.util.ArrayList) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) File(java.io.File)

Example 17 with CodeLocation

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

the class MavenParseExtractor method extract.

public Extraction extract(File pomXmlFile, MavenParseOptions mavenParseOptions) {
    try (InputStream pomXmlInputStream = new FileInputStream(pomXmlFile)) {
        // we have to create a new handler or the state of all handlers would be shared.
        // we could create a handler factory or some other indirection so it could be injected but for now we make a new one.
        PomDependenciesHandler pomDependenciesHandler = new PomDependenciesHandler(mavenParseOptions.isIncludePlugins());
        saxParser.parse(pomXmlInputStream, pomDependenciesHandler);
        List<Dependency> dependencies = pomDependenciesHandler.getDependencies();
        DependencyGraph dependencyGraph = new BasicDependencyGraph();
        dependencyGraph.addChildrenToRoot(dependencies);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return Extraction.success(codeLocation);
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PomDependenciesHandler(com.synopsys.integration.detectable.detectables.maven.parsing.parse.PomDependenciesHandler) FileInputStream(java.io.FileInputStream)

Example 18 with CodeLocation

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

the class NpmLockfilePackager method parseAndTransform.

public NpmPackagerResult parseAndTransform(@Nullable String packageJsonText, String lockFileText, List<NameVersion> externalDependencies) {
    PackageJson packageJson = Optional.ofNullable(packageJsonText).map(content -> gson.fromJson(content, PackageJson.class)).orElse(null);
    PackageLock packageLock = gson.fromJson(lockFileText, PackageLock.class);
    NpmDependencyConverter dependencyConverter = new NpmDependencyConverter(externalIdFactory);
    NpmProject project = dependencyConverter.convertLockFile(packageLock, packageJson);
    DependencyGraph dependencyGraph = graphTransformer.transform(packageLock, project, externalDependencies);
    ExternalId projectId = projectIdTransformer.transform(packageJson, packageLock);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph, projectId);
    return new NpmPackagerResult(projectId.getName(), projectId.getVersion(), codeLocation);
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) Nullable(org.jetbrains.annotations.Nullable) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NpmDependencyConverter(com.synopsys.integration.detectable.detectables.npm.lockfile.NpmDependencyConverter) Gson(com.google.gson.Gson) NpmProject(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult) Optional(java.util.Optional) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PackageLock(com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock) PackageLock(com.synopsys.integration.detectable.detectables.npm.lockfile.model.PackageLock) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NpmProject(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmProject) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) NpmDependencyConverter(com.synopsys.integration.detectable.detectables.npm.lockfile.NpmDependencyConverter) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)

Example 19 with CodeLocation

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

the class PackageJsonExtractor method extract.

public Extraction extract(PackageJson packageJson) {
    List<Dependency> dependencies = transformDependencies(packageJson.dependencies);
    npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.DEV, transformDependencies(packageJson.devDependencies), dependencies::addAll);
    npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.PEER, transformDependencies(packageJson.peerDependencies), dependencies::addAll);
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    dependencyGraph.addChildrenToRoot(dependencies);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    String projectName = StringUtils.stripToNull(packageJson.name);
    String projectVersion = StringUtils.stripToNull(packageJson.version);
    return new Extraction.Builder().success(codeLocation).projectName(projectName).projectVersion(projectVersion).build();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) 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)

Example 20 with CodeLocation

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

the class GradleReportTransformer method transform.

public CodeLocation transform(GradleReport gradleReport) {
    DependencyGraph graph = new BasicDependencyGraph();
    for (GradleConfiguration configuration : gradleReport.getConfigurations()) {
        if (configuration.isResolved() || configurationTypeFilter.shouldInclude(GradleConfigurationType.UNRESOLVED)) {
            logger.trace("Adding configuration to the graph: {}", configuration.getName());
            addConfigurationToGraph(graph, configuration);
        } else {
            logger.trace("Excluding unresolved configuration from the graph: {}", configuration.getName());
        }
    }
    ExternalId projectId = ExternalId.FACTORY.createMavenExternalId(gradleReport.getProjectGroup(), gradleReport.getProjectName(), gradleReport.getProjectVersionName());
    if (StringUtils.isNotBlank(gradleReport.getProjectSourcePath())) {
        return new CodeLocation(graph, projectId, new File(gradleReport.getProjectSourcePath()));
    } else {
        return new CodeLocation(graph, projectId);
    }
}
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) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) GradleConfiguration(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleConfiguration) File(java.io.File)

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