use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class YarnListParserTest method testThatYarnListLineAtBeginningIsIgnored.
@Test
public void testThatYarnListLineAtBeginningIsIgnored() {
final List<String> designedYarnLock = new ArrayList<>();
designedYarnLock.add("abab@5.5.2:");
designedYarnLock.add(" version \"5.5.2\"");
designedYarnLock.add("");
final List<String> testLines = new ArrayList<>();
testLines.add("yarn list v1.5.1");
testLines.add("├─ abab@1.0.4");
final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
final YarnLockParser yarnLockParser = new YarnLockParser();
final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
assertNotNull(tempList.get(0));
assertEquals(1, tempList.size());
}
use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class YarnListParserTest method testThatYarnListWithGrandchildIsParsedCorrectly.
@Test
public void testThatYarnListWithGrandchildIsParsedCorrectly() {
final List<String> designedYarnLock = new ArrayList<>();
designedYarnLock.add("yargs-parser@5.5.2:");
designedYarnLock.add(" version \"5.5.2\"");
designedYarnLock.add("");
designedYarnLock.add("camelcase@^3.0.0:");
designedYarnLock.add(" version \"5.5.2\"");
designedYarnLock.add("");
final List<String> testLines = new ArrayList<>();
testLines.add("├─ yargs-parser@4.2.1");
testLines.add("│ └─ camelcase@^3.0.0");
final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
final YarnLockParser yarnLockParser = new YarnLockParser();
final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
List<ExternalId> kidsList = new ArrayList<>();
for (int i = 0; i < tempList.size(); i++) {
if ("yargs-parser".equals(tempList.get(i).name)) {
kidsList = new ArrayList<>(dependencyGraph.getChildrenExternalIdsForParent(tempList.get(i)));
}
}
assertListContainsDependency("yargs-parser", "4.2.1", tempList);
assertListContainsDependency("camelcase", "5.5.2", kidsList);
}
use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class YarnListParserTest method testDependencyInYarnListAndNotInLock.
@Test
public void testDependencyInYarnListAndNotInLock() {
final List<String> designedYarnLock = new ArrayList<>();
designedYarnLock.add("ajv@5.5.2:");
designedYarnLock.add(" version \"5.5.2\"");
designedYarnLock.add("");
final List<String> testLines = new ArrayList<>();
testLines.add("yarn list v1.5.1");
testLines.add("├─ abab@1.0.4");
final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
final YarnLockParser yarnLockParser = new YarnLockParser();
final YarnListParser yarnListParser = new YarnListParser(externalIdFactory, yarnLockParser);
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(designedYarnLock, testLines);
final List<ExternalId> tempList = new ArrayList<>(dependencyGraph.getRootDependencyExternalIds());
assertEquals(1, tempList.size());
assertListContainsDependency("abab", "1.0.4", tempList);
}
use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class PodlockParser method extractDependencyGraph.
public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
final YAMLMapper mapper = new YAMLMapper();
final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock);
for (final Pod pod : podfileLock.pods) {
logger.trace(String.format("Processing pod %s", pod.name));
processPod(pod, forgeOverrides, lazyBuilder);
}
for (final Pod dependency : podfileLock.dependencies) {
logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.name));
final String podText = dependency.name;
final Optional<DependencyId> dependencyId = parseDependencyId(podText);
if (dependencyId.isPresent()) {
lazyBuilder.addChildToRoot(dependencyId.get());
}
}
logger.trace("Attempting to build the dependency graph.");
final DependencyGraph dependencyGraph = lazyBuilder.build();
logger.trace("Completed the dependency graph.");
return dependencyGraph;
}
use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class CondaCliExtractor method extract.
public Extraction extract(final File directory, final File condaExe, ExtractionId extractionId) {
try {
File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
final List<String> condaListOptions = new ArrayList<>();
condaListOptions.add("list");
final String condaEnvironmentName = detectConfiguration.getProperty(DetectProperty.DETECT_CONDA_ENVIRONMENT_NAME, PropertyAuthority.None);
if (StringUtils.isNotBlank(condaEnvironmentName)) {
condaListOptions.add("-n");
condaListOptions.add(condaEnvironmentName);
}
condaListOptions.add("--json");
final Executable condaListExecutable = new Executable(directory, condaExe, condaListOptions);
final ExecutableOutput condaListOutput = executableRunner.execute(condaListExecutable);
final String listJsonText = condaListOutput.getStandardOutput();
final ExecutableOutput condaInfoOutput = executableRunner.execute(workingDirectory, condaExe, "info", "--json");
final String infoJsonText = condaInfoOutput.getStandardOutput();
final DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.ANACONDA, directory.toString());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CONDA, directory.toString(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations