Search in sources :

Example 1 with LernaResult

use of com.synopsys.integration.detectable.detectables.lerna.model.LernaResult in project synopsys-detect by blackducksoftware.

the class LernaExtractor method extract.

public Extraction extract(File sourceDirectory, File packageJson, ExecutableTarget lernaExecutable) {
    try {
        List<LernaPackage> lernaPackages = lernaPackageDiscoverer.discoverLernaPackages(sourceDirectory, lernaExecutable);
        LernaResult lernaResult = lernaPackager.generateLernaResult(sourceDirectory, packageJson, lernaPackages);
        if (lernaResult.getException().isPresent()) {
            throw lernaResult.getException().get();
        }
        return new Extraction.Builder().projectName(lernaResult.getProjectName()).projectVersion(lernaResult.getProjectVersionName()).success(lernaResult.getCodeLocations()).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : LernaResult(com.synopsys.integration.detectable.detectables.lerna.model.LernaResult) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 2 with LernaResult

use of com.synopsys.integration.detectable.detectables.lerna.model.LernaResult 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)

Aggregations

LernaPackage (com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage)2 LernaResult (com.synopsys.integration.detectable.detectables.lerna.model.LernaResult)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 EnumListFilter (com.synopsys.integration.detectable.detectable.util.EnumListFilter)1 LernaLockFileResult (com.synopsys.integration.detectable.detectables.lerna.lockfile.LernaLockFileResult)1 NpmLockfilePackager (com.synopsys.integration.detectable.detectables.npm.lockfile.parse.NpmLockfilePackager)1 NpmPackagerResult (com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)1 YarnPackager (com.synopsys.integration.detectable.detectables.yarn.YarnPackager)1 YarnResult (com.synopsys.integration.detectable.detectables.yarn.YarnResult)1 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)1 PackageJsonReader (com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader)1 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)1 YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)1 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)1 NameVersion (com.synopsys.integration.util.NameVersion)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1