Search in sources :

Example 1 with PackageDetails

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;
}
Also used : PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PackageDetails

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)

Example 3 with PackageDetails

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());
}
Also used : PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)

Example 4 with PackageDetails

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());
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) HashSet(java.util.HashSet) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) Test(org.junit.jupiter.api.Test)

Example 5 with PackageDetails

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);
}
Also used : ClangPackageManagerInfo(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfo) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) RpmPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.RpmPackageManagerResolver) Gson(com.google.gson.Gson) File(java.io.File) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

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