use of com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation in project synopsys-detect by blackducksoftware.
the class PipInspectorTreeParserTest method validTest.
@Test
public void validTest() {
List<String> pipInspectorOutput = Arrays.asList("projectName==projectVersionName", " with-dashes==1.0.0", " Uppercase==2.0.0", " child==3.0.0", " test==4.0.0");
Optional<NameVersionCodeLocation> validParse = parser.parse(pipInspectorOutput, "");
Assertions.assertTrue(validParse.isPresent());
Assertions.assertEquals("projectName", validParse.get().getProjectName());
Assertions.assertEquals("projectVersionName", validParse.get().getProjectVersion());
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, validParse.get().getCodeLocation().getDependencyGraph());
graphAssert.hasRootDependency("with-dashes", "1.0.0");
graphAssert.hasRootDependency("Uppercase", "2.0.0");
graphAssert.hasRootDependency("test", "4.0.0");
graphAssert.hasParentChildRelationship("Uppercase", "2.0.0", "child", "3.0.0");
graphAssert.hasRootSize(3);
}
use of com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation in project synopsys-detect by blackducksoftware.
the class PipInspectorExtractor method extract.
public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipExe, File pipInspector, File setupFile, List<Path> requirementFilePaths, String providedProjectName) {
toolVersionLogger.log(directory, pythonExe);
toolVersionLogger.log(directory, pipExe);
Extraction extractionResult;
try {
String projectName = getProjectName(directory, pythonExe, setupFile, providedProjectName);
List<CodeLocation> codeLocations = new ArrayList<>();
String projectVersion = null;
List<Path> requirementsPaths = new ArrayList<>();
if (requirementFilePaths.isEmpty()) {
requirementsPaths.add(null);
} else {
requirementsPaths.addAll(requirementFilePaths);
}
for (Path requirementFilePath : requirementsPaths) {
List<String> inspectorOutput = runInspector(directory, pythonExe, pipInspector, projectName, requirementFilePath);
Optional<NameVersionCodeLocation> result = pipInspectorTreeParser.parse(inspectorOutput, directory.toString());
if (result.isPresent()) {
codeLocations.add(result.get().getCodeLocation());
String potentialProjectVersion = result.get().getProjectVersion();
if (projectVersion == null && StringUtils.isNotBlank(potentialProjectVersion)) {
projectVersion = potentialProjectVersion;
}
}
}
if (codeLocations.isEmpty()) {
extractionResult = new Extraction.Builder().failure("The Pip Inspector tree parse failed to produce output.").build();
} else {
extractionResult = new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
}
} catch (Exception e) {
extractionResult = new Extraction.Builder().exception(e).build();
}
return extractionResult;
}
use of com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation 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);
}
Aggregations