use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.
the class PearPackageDependenciesParser method parse.
public List<PackageDependency> parse(List<String> packageDependenciesLines) throws IntegrationException {
List<PackageDependency> packageDependencies = new ArrayList<>();
boolean started = false;
for (String rawLine : packageDependenciesLines) {
String line = rawLine.trim();
if (!started) {
started = line.startsWith(START_TOKEN);
continue;
} else if (StringUtils.isBlank(line) || line.startsWith("Required") || line.startsWith("REQUIRED")) {
continue;
}
String[] entry = line.split(" +");
if (entry.length < 3) {
throw new IntegrationException("Unable to parse package-dependencies");
}
boolean required = BooleanUtils.toBoolean(entry[0]);
String type = entry[1].trim();
String[] namePieces = entry[2].split("/");
String name = namePieces[namePieces.length - 1].trim();
if ("Package".equalsIgnoreCase(type)) {
PackageDependency packageDependency = new PackageDependency(name, required);
packageDependencies.add(packageDependency);
}
}
return packageDependencies;
}
use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.
the class PearDependencyGraphTransformerTest method buildDependencyGraph.
private DependencyGraph buildDependencyGraph(PearDependencyType... excludedTypes) {
ExternalIdFactory externalIdFactory = new ExternalIdFactory();
PearDependencyGraphTransformer pearDependencyGraphTransformer = new PearDependencyGraphTransformer(externalIdFactory, EnumListFilter.fromExcluded(excludedTypes));
Map<String, String> nameVersionMap = new HashMap<>();
nameVersionMap.put("Archive_Tar", "1.4.3");
nameVersionMap.put("Console_Getopt", "1.4.1");
List<PackageDependency> packageDependencies = new ArrayList<>();
packageDependencies.add(new PackageDependency("Archive_Tar", true));
packageDependencies.add(new PackageDependency("Console_Getopt", false));
return pearDependencyGraphTransformer.buildDependencyGraph(nameVersionMap, packageDependencies);
}
use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.
the class PearCliExtractor method extract.
public Extraction extract(ExecutableTarget pearExe, File packageXmlFile, File workingDirectory) {
try {
ExecutableOutput pearListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "list"));
ExecutableOutput packageDependenciesOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME));
assertValidExecutableOutput(pearListOutput, packageDependenciesOutput);
Map<String, String> dependencyNameVersionMap = pearListParser.parse(pearListOutput.getStandardOutputAsList());
List<PackageDependency> packageDependencies = pearPackageDependenciesParser.parse(packageDependenciesOutput.getStandardOutputAsList());
DependencyGraph dependencyGraph = pearDependencyGraphTransformer.buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
try (InputStream packageXmlInputStream = new FileInputStream(packageXmlFile)) {
NameVersion projectNameVersion = pearPackageXmlParser.parse(packageXmlInputStream);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, projectNameVersion.getName(), projectNameVersion.getVersion());
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, externalId);
return new Extraction.Builder().success(detectCodeLocation).projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()).build();
}
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.
the class PearDependencyGraphTransformer method buildDependencyGraph.
public DependencyGraph buildDependencyGraph(Map<String, String> dependencyNameVersionMap, List<PackageDependency> packageDependencies) {
List<Dependency> dependencies = packageDependencies.stream().filter(this::filterDependencyType).map(PackageDependency::getName).map(dependencyName -> {
String dependencyVersion = dependencyNameVersionMap.get(dependencyName);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, dependencyName, dependencyVersion);
return new Dependency(dependencyName, dependencyVersion, externalId);
}).collect(Collectors.toList());
DependencyGraph mutableDependencyGraph = new BasicDependencyGraph();
mutableDependencyGraph.addChildrenToRoot(dependencies);
return mutableDependencyGraph;
}
use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.
the class PearRequiredOnlyTest method TestParse.
@Test
public void TestParse() throws IntegrationException {
List<String> pearList = Arrays.asList("Installed packages, channel pear.php.net:", "=========================================", "Package Version State", "Archive_Tar 1.4.3 stable", "Auth_SASL 1.1.0 stable", "Config 1.10.12 stable", "Console_Getopt 1.4.1 stable", "HTML_Template_IT 1.3.0 stable", "MIME_Type 1.4.1 stable", "Net_SMTP 1.8.0 stable", "Net_Socket 1.2.2 stable", "PEAR 1.10.5 stable", "PEAR_Frontend_Gtk 0.4.0 beta", "PEAR_Frontend_Web 0.7.5 beta", "Structures_Graph 1.1.1 stable", "XML_Util 1.4.2 stable");
List<String> pearPackageDependencies = Arrays.asList("Dependencies for Net_SMTP", "=========================", "Required? Type Name Versioning Group", "Yes Php (version >= 5.4.0)", "Yes Pear Installer (version >= 1.10.1)", "Yes Package pear/Net_Socket (version >= 1.0.7)", "No Package pear/Auth_SASL (version >= 1.0.5)");
ExternalIdFactory factory = new ExternalIdFactory();
Map<String, String> dependencyNameVersionMap = new PearListParser().parse(pearList);
List<PackageDependency> packageDependencies = new PearPackageDependenciesParser().parse(pearPackageDependencies);
DependencyGraph dependencyGraph = new PearDependencyGraphTransformer(factory, EnumListFilter.excludeNone()).buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
Assertions.assertTrue(dependencyGraph.hasDependency(factory.createNameVersionExternalId(Forge.PEAR, "Auth_SASL", "1.1.0")), "Must have Auth_SASL even though it was not a required dependency.");
}
Aggregations