use of com.synopsys.integration.detectable.detectables.lerna.lockfile.LernaLockFileResult in project synopsys-detect by blackducksoftware.
the class LernaPackager method extractPackage.
@Nullable
private LernaResult extractPackage(LernaPackage lernaPackage, List<NameVersion> externalPackages, LernaLockFileResult rootLockFile) {
String lernaPackageDetails = String.format("%s:%s at %s", lernaPackage.getName(), lernaPackage.getVersion(), lernaPackage.getLocation());
if (lernaPackage.isPrivate() && lernaPackageTypeFilter.shouldExclude(LernaPackageType.PRIVATE)) {
logger.debug("Skipping extraction of private lerna package {}.", lernaPackageDetails);
return null;
}
logger.debug("Now extracting Lerna package {}.", lernaPackageDetails);
File lernaPackageDirectory = new File(lernaPackage.getLocation());
LernaLockFileResult lockFile = findLockFiles(lernaPackageDirectory);
File packagesPackageJson = fileFinder.findFile(lernaPackageDirectory, LernaDetectable.PACKAGE_JSON);
if (packagesPackageJson == null) {
return LernaResult.failure(new FileNotFoundException(String.format("A %s file was not found in %s.", LernaDetectable.PACKAGE_JSON, lernaPackageDirectory.getAbsolutePath())));
}
if (lockFile.hasLockFile()) {
return parse(lernaPackageDirectory, packagesPackageJson, lockFile, externalPackages);
} else {
return parse(lernaPackageDirectory, packagesPackageJson, rootLockFile, externalPackages);
}
}
use of com.synopsys.integration.detectable.detectables.lerna.lockfile.LernaLockFileResult 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);
}
Aggregations