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();
}
}
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);
}
Aggregations