Search in sources :

Example 16 with PackageDetails

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

the class ApkPackageManagerTest method canParsePackages.

@Test
public void canParsePackages() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("this line has the is owned by substring\n");
    sb.append(" is owned by \n");
    // This is the one valid line; rest should be discarded
    sb.append("/usr/include/stdlib.h is owned by musl-dev-1.1.18-r3\n");
    sb.append("/usr/include/stdlib.h is owned by .musl-dev-1.1.18-r99\n");
    String pkgMgrOwnedByOutput = sb.toString();
    ApkArchitectureResolver architectureResolver = Mockito.mock(ApkArchitectureResolver.class);
    Mockito.when(architectureResolver.resolveArchitecture(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Optional.of("x86_64"));
    ApkPackageManagerResolver apkPackageManagerResolver = new ApkPackageManagerResolver(architectureResolver);
    ClangPackageManagerInfo apk = new ClangPackageManagerInfoFactory().apk();
    List<PackageDetails> pkgs = apkPackageManagerResolver.resolvePackages(apk, null, null, pkgMgrOwnedByOutput);
    Assertions.assertEquals(1, pkgs.size());
    Assertions.assertEquals("musl-dev", pkgs.get(0).getPackageName());
    Assertions.assertEquals("1.1.18-r3", pkgs.get(0).getPackageVersion());
    Assertions.assertEquals("x86_64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) ClangPackageManagerInfo(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfo) ApkArchitectureResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.ApkArchitectureResolver) ApkPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.ApkPackageManagerResolver) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 17 with PackageDetails

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

the class ClangPackageDetailsTransformerTest method doTest.

private void doTest(Forge forge) {
    ExternalIdFactory externalIdFactory = Mockito.mock(ExternalIdFactory.class);
    ClangPackageDetailsTransformer transformer = new ClangPackageDetailsTransformer(externalIdFactory);
    Forge codeLocationForge = null;
    List<Forge> dependencyForges = new ArrayList<>();
    dependencyForges.add(forge);
    File rootDir = null;
    Set<PackageDetails> packages = new HashSet<>();
    final String packageName = "testPkgName";
    final String packageVersion = "1:testPkgVersion";
    final String packageArch = "testArch";
    PackageDetails pkg = new PackageDetails(packageName, packageVersion, packageArch);
    packages.add(pkg);
    ExternalId externalId = new ExternalId(forge);
    externalId.setName(packageName);
    externalId.setVersion(packageVersion);
    externalId.setArchitecture(packageArch);
    // The real test is: Does this get called: (if not, test will fail)
    Mockito.when(externalIdFactory.createArchitectureExternalId(forge, packageName, packageVersion, packageArch)).thenReturn(externalId);
    CodeLocation codeLocation = transformer.toCodeLocation(dependencyForges, packages);
    assertEquals(1, codeLocation.getDependencyGraph().getRootDependencies().size());
    Dependency generatedDependency = codeLocation.getDependencyGraph().getRootDependencies().iterator().next();
    assertEquals(packageName, generatedDependency.getName());
    assertEquals(packageVersion, generatedDependency.getVersion());
    assertEquals(forge, generatedDependency.getExternalId().getForge());
    String expectedExternalId = String.format("%s/%s/%s", packageName, packageVersion, packageArch);
    assertEquals(expectedExternalId, generatedDependency.getExternalId().createExternalId());
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) Forge(com.synopsys.integration.bdio.model.Forge) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) File(java.io.File) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) HashSet(java.util.HashSet)

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