use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class CondaCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget condaExe, File workingDirectory, String condaEnvironmentName) {
try {
toolVersionLogger.log(workingDirectory, condaExe);
List<String> condaListOptions = new ArrayList<>();
condaListOptions.add("list");
if (StringUtils.isNotBlank(condaEnvironmentName)) {
condaListOptions.add("-n");
condaListOptions.add(condaEnvironmentName);
}
condaListOptions.add("--json");
ExecutableOutput condaListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, condaExe, condaListOptions));
String listJsonText = condaListOutput.getStandardOutput();
ExecutableOutput condaInfoOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, condaExe, "info", "--json"));
String infoJsonText = condaInfoOutput.getStandardOutput();
DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(detectCodeLocation).build();
} 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 GoGradleExtractor method extract.
public Extraction extract(File goGradleLockFile) {
try {
DependencyGraph dependencyGraph = goGradleLockParser.parse(goGradleLockFile);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (IOException | IntegrationException 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 GoModCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget goExe) throws ExecutableFailedException, JsonSyntaxException, DetectableException {
List<GoListModule> goListModules = listModules(directory, goExe);
List<GoListAllData> goListAllModules = listAllModules(directory, goExe);
List<GoGraphRelationship> goGraphRelationships = listGraphRelationships(directory, goExe);
Set<String> excludedModules = listExcludedModules(directory, goExe);
GoRelationshipManager goRelationshipManager = new GoRelationshipManager(goGraphRelationships, excludedModules);
GoModDependencyManager goModDependencyManager = new GoModDependencyManager(goListAllModules, externalIdFactory);
List<CodeLocation> codeLocations = goListModules.stream().map(goListModule -> goModGraphGenerator.generateGraph(goListModule, goRelationshipManager, goModDependencyManager)).collect(Collectors.toList());
// No project info - hoping git can help with that.
return new Extraction.Builder().success(codeLocations).build();
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PackagistParser method getDependencyGraphFromProject.
// TODO: Why are we dealing with JsonObjects rather than Gson straight to classes? Is this to avoid TypeAdapters? If so... smh JM-01/2022
public PackagistParseResult getDependencyGraphFromProject(String composerJsonText, String composerLockText) throws MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder builder = new LazyExternalIdDependencyGraphBuilder();
JsonObject composerJsonObject = new JsonParser().parse(composerJsonText).getAsJsonObject();
NameVersion projectNameVersion = parseNameVersionFromJson(composerJsonObject);
JsonObject composerLockObject = new JsonParser().parse(composerLockText).getAsJsonObject();
List<PackagistPackage> models = convertJsonToModel(composerLockObject);
List<NameVersion> rootPackages = parseDependencies(composerJsonObject);
models.forEach(it -> {
ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, it.getNameVersion().getName(), it.getNameVersion().getVersion());
LazyId dependencyId = LazyId.fromName(it.getNameVersion().getName());
builder.setDependencyInfo(dependencyId, it.getNameVersion().getName(), it.getNameVersion().getVersion(), id);
if (isRootPackage(it.getNameVersion(), rootPackages)) {
builder.addChildToRoot(dependencyId);
}
it.getDependencies().forEach(child -> {
if (existsInPackages(child, models)) {
LazyId childId = LazyId.fromName(child.getName());
builder.addChildWithParent(childId, dependencyId);
} else {
logger.warn("Dependency was not found in packages list but found a require that used it: " + child.getName());
}
});
});
DependencyGraph graph = builder.build();
CodeLocation codeLocation;
if (projectNameVersion.getName() == null || projectNameVersion.getVersion() == null) {
codeLocation = new CodeLocation(graph);
} else {
codeLocation = new CodeLocation(graph, externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, projectNameVersion.getName(), projectNameVersion.getVersion()));
}
return new PackagistParseResult(projectNameVersion.getName(), projectNameVersion.getVersion(), codeLocation);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class IvyParseExtractor method extract.
public Extraction extract(File ivyXmlFile, File buildXmlFile) throws IOException {
try (InputStream ivyXmlInputStream = new FileInputStream(ivyXmlFile)) {
IvyDependenciesHandler ivyDependenciesHandler = new IvyDependenciesHandler(externalIdFactory);
saxParser.parse(ivyXmlInputStream, ivyDependenciesHandler);
List<Dependency> dependencies = ivyDependenciesHandler.getDependencies();
DependencyGraph dependencyGraph = new BasicDependencyGraph();
dependencyGraph.addChildrenToRoot(dependencies);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
Optional<NameVersion> projectName = projectNameParser.parseProjectName(buildXmlFile);
return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(projectName).build();
} catch (SAXException e) {
return new Extraction.Builder().failure(String.format("There was an error parsing file %s: %s", ivyXmlFile.getAbsolutePath(), e.getMessage())).build();
}
}
Aggregations