use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class RpmPackageManagerResolver method buildPackageDetails.
@NotNull
private PackageDetails buildPackageDetails(RpmPackage rpmPackage) {
String packageName = rpmPackage.getName();
String packageVersion = rpmPackage.getVersion();
String epoch = rpmPackage.getEpoch();
if (!NO_VALUE.equals(epoch)) {
packageVersion = String.format("%s:%s", epoch, packageVersion);
}
String arch = "";
if (!NO_VALUE.equals(rpmPackage.getArch())) {
arch = rpmPackage.getArch();
}
PackageDetails dependencyDetails = new PackageDetails(packageName, packageVersion, arch);
return dependencyDetails;
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class ApkPackageManagerResolver method resolvePackages.
@Override
public List<PackageDetails> resolvePackages(ClangPackageManagerInfo currentPackageManager, DetectableExecutableRunner executableRunner, File workingDirectory, String queryPackageOutput) throws ExecutableRunnerException, NotOwnedByAnyPkgException {
isValid(queryPackageOutput);
Optional<String> architecture = architectureResolver.resolveArchitecture(currentPackageManager, workingDirectory, executableRunner);
List<PackageDetails> packageDetailsList = new ArrayList<>();
String[] packageLines = queryPackageOutput.split("\n");
for (String packageLine : packageLines) {
Optional<List<String>> pkgNameVersionParts = parseIsOwnedByOutputLine(packageLine);
if (pkgNameVersionParts.isPresent()) {
String version = deriveVersion(pkgNameVersionParts.get());
logger.trace(String.format("version: %s", version));
Optional<String> component = deriveComponent(pkgNameVersionParts.get());
logger.trace(String.format("component: %s", component));
if (component.isPresent()) {
String externalId = String.format("%s/%s/%s", component, version, architecture.get());
logger.debug(String.format("Constructed externalId: %s", externalId));
PackageDetails dependencyDetails = new PackageDetails(component.get(), version, architecture.get());
packageDetailsList.add(dependencyDetails);
}
}
}
return packageDetailsList;
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class ClangPackageManagerRunnerTest method testSuccessCase.
private void testSuccessCase(ClangPackageManagerInfo packageManagerInfo, ClangPackageManagerResolver packageResolver, String pkgName, String pkgArchitecture, boolean archBuried, String pkgVersion, String pkgMgrQueryResultPattern, String pkgMgrDetailsQueryResultPattern) throws ExecutableRunnerException {
// Test
PackageDetailsResult result = runTest(packageManagerInfo, packageResolver, pkgName, pkgArchitecture, archBuried, pkgMgrQueryResultPattern, pkgMgrDetailsQueryResultPattern, dependencyFile);
// Verify
assertEquals(0, result.getUnRecognizedDependencyFiles().size());
assertEquals(1, result.getFoundPackages().size());
PackageDetails foundPkgDetails = result.getFoundPackages().iterator().next();
assertEquals(pkgName, foundPkgDetails.getPackageName());
assertEquals(pkgArchitecture, foundPkgDetails.getPackageArch());
assertEquals(pkgVersion, foundPkgDetails.getPackageVersion());
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class DependencyFileDetailGeneratorTest method testDependencyCreatedWithEachForge.
@Test
public void testDependencyCreatedWithEachForge() {
File mockFile = Mockito.mock(File.class);
Mockito.when(mockFile.toString()).thenReturn("Example");
Set<PackageDetails> packages = new HashSet<>();
packages.add(new PackageDetails("testPackageName1", "testPackageVersion1", "testPackageArch1"));
packages.add(new PackageDetails("testPackageName2", "testPackageVersion2", "testPackageArch2"));
ExternalIdFactory externalIdFactory = new ExternalIdFactory();
ClangPackageDetailsTransformer clangPackageDetailsTransformer = new ClangPackageDetailsTransformer(externalIdFactory);
CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(Arrays.asList(Forge.CENTOS, Forge.FEDORA, Forge.REDHAT), packages);
Set<Dependency> dependencies = codeLocation.getDependencyGraph().getRootDependencies();
assertEquals(6, dependencies.size());
for (Dependency dependency : dependencies) {
System.out.printf("Checking dependency: %s:%s / %s\n", dependency.getName(), dependency.getVersion(), dependency.getExternalId().getForge().getName());
char indexChar = dependency.getName().charAt(15);
assertTrue(indexChar == '1' || indexChar == '2' || indexChar == '3');
String forge = dependency.getExternalId().getForge().getName();
assertTrue("centos".equals(forge) || "fedora".equals(forge) || "redhat".equals(forge));
assertEquals(String.format("testPackageName%c", indexChar), dependency.getName());
assertEquals(String.format("testPackageVersion%c", indexChar), dependency.getVersion());
assertEquals(String.format("testPackageArch%c", indexChar), dependency.getExternalId().getArchitecture());
assertEquals(forge, dependency.getExternalId().getForge().getName());
assertEquals(String.format("testPackageName%c", indexChar), dependency.getExternalId().getName());
assertEquals(String.format("testPackageVersion%c", indexChar), dependency.getExternalId().getVersion());
}
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.
the class RpmPackageManagerTest method testResolve.
@Test
public void testResolve() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
RpmPackageManagerResolver resolver = new RpmPackageManagerResolver(new Gson());
ClangPackageManagerInfo currentPackageManager = null;
DetectableExecutableRunner executableRunner = null;
File workingDirectory = null;
final String queryPackageOutput = "{ epoch: \"(none)\", name: \"glibc-headers\", version: \"2.17-222.el7\", arch: \"x86_64\" }\n" + "{ epoch: \"3\", name: \"test-package\", version: \"test-version\", arch: \"test_arch\" }\n";
List<PackageDetails> pkgs = resolver.resolvePackages(currentPackageManager, executableRunner, workingDirectory, queryPackageOutput);
assertEquals(2, pkgs.size());
boolean foundGLibcHeaders = false;
boolean foundTestPkg = false;
for (PackageDetails pkg : pkgs) {
if (pkg.getPackageName().equals("glibc-headers")) {
foundGLibcHeaders = true;
assertEquals("2.17-222.el7", pkg.getPackageVersion());
assertEquals("x86_64", pkg.getPackageArch());
}
if (pkg.getPackageName().equals("test-package")) {
foundTestPkg = true;
assertEquals("3:test-version", pkg.getPackageVersion());
assertEquals("test_arch", pkg.getPackageArch());
}
}
assertTrue(foundGLibcHeaders);
assertTrue(foundTestPkg);
}
Aggregations