Search in sources :

Example 6 with PackageDetails

use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.

the class RpmPackageManagerTest method testValidWithEpoch.

@Test
public void testValidWithEpoch() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("{ epoch: \"9\", name: \"boost-devel\", version: \"1.53.0-27.el7\", arch: \"x86_64\" }\n");
    String pkgMgrOwnedByOutput = sb.toString();
    RpmPackageManagerResolver pkgMgr = new RpmPackageManagerResolver(new Gson());
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().rpm(), null, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("boost-devel", pkgs.get(0).getPackageName());
    assertEquals("9:1.53.0-27.el7", pkgs.get(0).getPackageVersion());
    assertEquals("x86_64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) RpmPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.RpmPackageManagerResolver) Gson(com.google.gson.Gson) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 7 with PackageDetails

use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.

the class RpmPackageManagerTest method testParseSingleVariant.

@Test
public void testParseSingleVariant() throws NotOwnedByAnyPkgException {
    RpmPackageManagerResolver resolver = new RpmPackageManagerResolver(new Gson());
    final String queryPackageOutputLine = "{ epoch: \"(none)\", name: \"glibc-headers\", version: \"2.28-101.el8\", arch: \"x86_64\" }";
    Optional<PackageDetails> pkg = resolver.generatePackageFromQueryOutputLine(queryPackageOutputLine);
    assertTrue(pkg.isPresent());
    assertEquals("glibc-headers", pkg.get().getPackageName());
    assertEquals("2.28-101.el8", pkg.get().getPackageVersion());
}
Also used : RpmPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.RpmPackageManagerResolver) Gson(com.google.gson.Gson) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 8 with PackageDetails

use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.

the class RpmPackageManagerTest method testValidNoEpoch.

@Test
public void testValidNoEpoch() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("{ epoch: \"(none)\", name: \"boost-devel\", version: \"1.53.0-27.el7\", arch: \"x86_64\" }\n");
    String pkgMgrOwnedByOutput = sb.toString();
    RpmPackageManagerResolver pkgMgr = new RpmPackageManagerResolver(new Gson());
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().rpm(), null, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("boost-devel", pkgs.get(0).getPackageName());
    assertEquals("1.53.0-27.el7", pkgs.get(0).getPackageVersion());
    assertEquals("x86_64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) RpmPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.RpmPackageManagerResolver) Gson(com.google.gson.Gson) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 9 with PackageDetails

use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.

the class RpmPackageManagerResolver method generatePackageFromQueryOutputLine.

public Optional<PackageDetails> generatePackageFromQueryOutputLine(String queryOutputLine) throws NotOwnedByAnyPkgException {
    logger.trace(String.format("packageLine: %s", queryOutputLine));
    Optional<String> packageJson = extractPackageJson(queryOutputLine);
    if (!packageJson.isPresent()) {
        logger.debug(String.format("Skipping line: %s (not a package)", queryOutputLine));
        return Optional.empty();
    }
    RpmPackage rpmPackage;
    try {
        rpmPackage = gson.fromJson(packageJson.get(), RpmPackage.class);
    } catch (JsonSyntaxException e) {
        logger.warn(String.format("Skipping rpm 'who owns this file' query output line: %s (invalid JSON syntax)", queryOutputLine));
        return Optional.empty();
    }
    PackageDetails dependencyDetails = buildPackageDetails(rpmPackage);
    return Optional.of(dependencyDetails);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)

Example 10 with PackageDetails

use of com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails in project synopsys-detect by blackducksoftware.

the class DpkgPkgDetailsResolver method parsePackageDetailsFromInfoOutput.

private Optional<PackageDetails> parsePackageDetailsFromInfoOutput(String packageName, String packageInfoOutput) {
    String packageArchitecture = null;
    String packageVersion = null;
    String[] packageInfoOutputLines = packageInfoOutput.split("\\n");
    for (String packageInfoOutputLine : packageInfoOutputLines) {
        if (foundUninstalledStatus(packageName, packageInfoOutputLine)) {
            return Optional.empty();
        }
        packageArchitecture = parseNeededValueFromLineIfPresent(packageName, packageInfoOutputLine, "Architecture", packageArchitecture);
        packageVersion = parseNeededValueFromLineIfPresent(packageName, packageInfoOutputLine, "Version", packageVersion);
    }
    if ((packageVersion == null) || (packageArchitecture == null)) {
        logger.warn("Unable to determine all details for package {} (version: {}; architecture: {}); this package will be omitted from the output", packageName, packageVersion, packageArchitecture);
        return Optional.empty();
    }
    return Optional.of(new PackageDetails(packageName, packageVersion, packageArchitecture));
}
Also used : PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)

Aggregations

PackageDetails (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)17 Test (org.junit.jupiter.api.Test)10 Gson (com.google.gson.Gson)6 RpmPackageManagerResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.RpmPackageManagerResolver)6 ClangPackageManagerInfoFactory (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory)5 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)3 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Forge (com.synopsys.integration.bdio.model.Forge)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 ClangPackageDetailsTransformer (com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer)2 ClangPackageManagerInfo (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfo)2 DpkgPackageManagerResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver)2 DpkgPkgDetailsResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver)2 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)2 HashSet (java.util.HashSet)2 List (java.util.List)2