use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PipInspectorTreeParser method parse.
public Optional<NameVersionCodeLocation> parse(List<String> pipInspectorOutputAsList, String sourcePath) {
NameVersionCodeLocation parseResult = null;
DependencyGraph graph = new BasicDependencyGraph();
DependencyHistory history = new DependencyHistory();
Dependency project = null;
int unResolvedPackageCount = 0;
for (String line : pipInspectorOutputAsList) {
String trimmedLine = StringUtils.trimToEmpty(line);
if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
boolean wasUnresolved = parseErrorsFromLine(trimmedLine);
if (wasUnresolved) {
unResolvedPackageCount++;
}
continue;
}
Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
adjustForIndentLevel(history, line);
project = addDependencyToGraph(graph, history, project, currentDependency);
history.add(currentDependency);
}
adviseIfUnresolvedPackages(unResolvedPackageCount);
if (project != null) {
CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
parseResult = new NameVersionCodeLocation(project.getName(), project.getVersion(), codeLocation);
}
return Optional.ofNullable(parseResult);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PipenvExtractor method extract.
public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipenvExe, File setupFile, String providedProjectName, String providedProjectVersionName, boolean includeOnlyProjectTree) {
Extraction extraction;
try {
String projectName = resolveProjectName(directory, pythonExe, setupFile, providedProjectName);
String projectVersionName = resolveProjectVersionName(directory, pythonExe, setupFile, providedProjectVersionName);
ExecutableOutput pipFreezeOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("run", "pip", "freeze")));
ExecutableOutput graphOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("graph", "--bare", "--json-tree")));
PipFreeze pipFreeze = pipenvFreezeParser.parse(pipFreezeOutput.getStandardOutputAsList());
PipenvGraph pipenvGraph = pipEnvJsonGraphParser.parse(graphOutput.getStandardOutput());
CodeLocation codeLocation = pipenvTransformer.transform(projectName, projectVersionName, pipFreeze, pipenvGraph, includeOnlyProjectTree);
return new Extraction.Builder().projectName(projectName).projectVersion(projectVersionName).success(codeLocation).build();
} catch (Exception e) {
extraction = new Extraction.Builder().exception(e).build();
}
return extraction;
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PipenvTransformer method transform.
public CodeLocation transform(String projectName, String projectVersionName, PipFreeze pipFreeze, PipenvGraph pipenvGraph, boolean includeOnlyProjectTree) {
DependencyGraph dependencyGraph = new BasicDependencyGraph();
for (PipenvGraphEntry entry : pipenvGraph.getEntries()) {
Dependency entryDependency = nameVersionToDependency(entry.getName(), entry.getVersion(), pipFreeze);
List<Dependency> children = addDependenciesToGraph(entry.getChildren(), dependencyGraph, pipFreeze);
if (matchesProject(entryDependency, projectName, projectVersionName)) {
// The project appears as an entry, we don't want the project to be a dependency of itself.
dependencyGraph.addChildrenToRoot(children);
} else if (!includeOnlyProjectTree) {
// Only add non-project matches if we are not project tree only.
dependencyGraph.addChildToRoot(entryDependency);
dependencyGraph.addParentWithChildren(entryDependency, children);
}
}
ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
return new CodeLocation(dependencyGraph, projectExternalId);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class RebarExtractor method extract.
public Extraction extract(File directory, ExecutableTarget rebarExe) {
try {
toolVersionLogger.log(directory, rebarExe);
List<CodeLocation> codeLocations = new ArrayList<>();
Map<String, String> envVars = new HashMap<>();
envVars.put("REBAR_COLOR", "none");
List<String> arguments = new ArrayList<>();
arguments.add("tree");
Executable rebar3TreeExe = ExecutableUtils.createFromTarget(directory, envVars, rebarExe, arguments);
List<String> output = executableRunner.execute(rebar3TreeExe).getStandardOutputAsList();
RebarParseResult parseResult = rebarTreeParser.parseRebarTreeOutput(output);
codeLocations.add(parseResult.getCodeLocation());
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
parseResult.getProjectNameVersion().ifPresent(projectNameVersion -> builder.projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()));
return builder.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 CodeLocationConverter method toDetectCodeLocation.
public Map<CodeLocation, DetectCodeLocation> toDetectCodeLocation(File detectSourcePath, DetectorEvaluation evaluation) {
Map<CodeLocation, DetectCodeLocation> detectCodeLocations = new HashMap<>();
if (evaluation.wasExtractionSuccessful()) {
Extraction extraction = evaluation.getExtraction();
String name = evaluation.getDetectorType().toString();
return toDetectCodeLocation(detectSourcePath, extraction, evaluation.getDetectableEnvironment().getDirectory(), name);
}
return detectCodeLocations;
}
Aggregations