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