Search in sources :

Example 36 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class ClangPackageManagerRunner method applies.

public boolean applies(ClangPackageManager currentPackageManager, File workingDirectory, DetectableExecutableRunner executor) {
    ClangPackageManagerInfo packageManagerInfo = currentPackageManager.getPackageManagerInfo();
    try {
        ExecutableOutput versionOutput = executor.execute(workingDirectory, packageManagerInfo.getPkgMgrName(), packageManagerInfo.getCheckPresenceCommandArgs());
        logger.debug(String.format("packageStatusOutput: %s", versionOutput.getStandardOutput()));
        if (versionOutput.getStandardOutput().contains(packageManagerInfo.getCheckPresenceCommandOutputExpectedText())) {
            logger.debug(String.format("Found package manager %s", packageManagerInfo.getPkgMgrName()));
            return true;
        }
        logger.debug(String.format("Output of %s %s does not look right; concluding that the %s package manager is not present. The output: %s", packageManagerInfo.getPkgMgrName(), packageManagerInfo.getCheckPresenceCommandArgs(), packageManagerInfo.getPkgMgrName(), versionOutput));
    } catch (ExecutableRunnerException e) {
        logger.debug(String.format("Error executing %s %s; concluding that the %s package manager is not present. The error: %s", packageManagerInfo.getPkgMgrName(), packageManagerInfo.getCheckPresenceCommandArgs(), packageManagerInfo.getPkgMgrName(), e.getMessage()));
        return false;
    }
    return false;
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException)

Example 37 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class ClangPackageManagerRunner method getPackages.

public PackageDetailsResult getPackages(ClangPackageManager currentPackageManager, File workingDirectory, DetectableExecutableRunner executableRunner, File dependencyFile) {
    ClangPackageManagerInfo packageManagerInfo = currentPackageManager.getPackageManagerInfo();
    Set<PackageDetails> dependencyDetails = new HashSet<>();
    Set<File> unRecognizedDependencyFiles = new HashSet<>();
    try {
        List<String> fileSpecificGetOwnerArgs = new ArrayList<>(packageManagerInfo.getPkgMgrGetOwnerCmdArgs());
        fileSpecificGetOwnerArgs.add(dependencyFile.getAbsolutePath());
        ExecutableOutput queryPackageResult = executableRunner.execute(workingDirectory, packageManagerInfo.getPkgMgrCmdString(), fileSpecificGetOwnerArgs);
        String queryPackageOutputToParse;
        if (StringUtils.isNotBlank(queryPackageResult.getStandardOutput())) {
            queryPackageOutputToParse = queryPackageResult.getStandardOutput();
        } else {
            queryPackageOutputToParse = queryPackageResult.getErrorOutput();
        }
        ClangPackageManagerResolver resolver = currentPackageManager.getPackageResolver();
        List<PackageDetails> packageDetails = resolver.resolvePackages(currentPackageManager.getPackageManagerInfo(), executableRunner, workingDirectory, queryPackageOutputToParse);
        dependencyDetails.addAll(packageDetails);
    } catch (NotOwnedByAnyPkgException notOwnedException) {
        logger.debug(String.format("%s is not recognized by the linux package manager (%s)", dependencyFile.getAbsolutePath(), notOwnedException.getMessage()));
        unRecognizedDependencyFiles.add(dependencyFile);
    } catch (ExecutableRunnerException e) {
        logger.debug(String.format("Error with dependency file %s when running %s", dependencyFile.getAbsolutePath(), packageManagerInfo.getPkgMgrCmdString()));
        logger.error(String.format("Error executing %s: %s", packageManagerInfo.getPkgMgrCmdString(), e.getMessage()));
    }
    return new PackageDetailsResult(dependencyDetails, unRecognizedDependencyFiles);
}
Also used : ArrayList(java.util.ArrayList) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NotOwnedByAnyPkgException(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.NotOwnedByAnyPkgException) ClangPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.ClangPackageManagerResolver) File(java.io.File) HashSet(java.util.HashSet)

Example 38 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class ApkArchitectureResolver method resolveArchitecture.

public Optional<String> resolveArchitecture(ClangPackageManagerInfo currentPackageManager, File workingDirectory, DetectableExecutableRunner executableRunner) throws ExecutableRunnerException {
    if (hasAttemptedResolution) {
        return architecture;
    }
    hasAttemptedResolution = true;
    if (currentPackageManager.getPkgArchitectureArgs().isPresent()) {
        List<String> args = currentPackageManager.getPkgArchitectureArgs().get();
        String cmd = currentPackageManager.getPkgMgrCmdString();
        ExecutableOutput architectureOutput = executableRunner.execute(workingDirectory, cmd, args);
        architecture = Optional.ofNullable(architectureOutput.getStandardOutput().trim());
    } else {
        architecture = Optional.empty();
    }
    return architecture;
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Example 39 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class DpkgPkgDetailsResolver method resolvePackageDetails.

public Optional<PackageDetails> resolvePackageDetails(ClangPackageManagerInfo currentPackageManager, DetectableExecutableRunner executableRunner, File workingDirectory, NameArchitecture packageNameArchitecture) {
    try {
        List<String> args = new ArrayList<>(currentPackageManager.getPkgInfoArgs().get());
        args.add(constructPackageArg(packageNameArchitecture.getName(), packageNameArchitecture.getArchitecture().orElse(null)));
        ExecutableOutput packageInfoOutput = executableRunner.execute(workingDirectory, currentPackageManager.getPkgMgrCmdString(), args);
        return parsePackageDetailsFromInfoOutput(packageNameArchitecture.getName(), packageInfoOutput.getStandardOutput());
    } catch (ExecutableRunnerException e) {
        logger.warn(String.format("Error executing %s to get package info: %s", currentPackageManager.getPkgMgrName(), e.getMessage()));
    }
    return Optional.empty();
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException)

Example 40 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class DpkgPackageManagerTest method testEpoch.

@Test
public void testEpoch() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("login:amd64: /usr/include/stdlib.h\n");
    String pkgMgrOwnedByOutput = sb.toString();
    sb = new StringBuilder();
    sb.append("Package: login\n");
    sb.append("Essential: yes\n");
    sb.append("Status: install ok installed\n");
    sb.append("Priority: required\n");
    sb.append("Section: admin\n");
    sb.append("Installed-Size: 1212\n");
    sb.append("Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\n");
    sb.append("Architecture: amd64\n");
    sb.append("Source: shadow\n");
    sb.append("Version: 1:4.5-1ubuntu1\n");
    sb.append("Replaces: manpages-de (<< 0.5-3), manpages-tr (<< 1.0.5), manpages-zh (<< 1.5.1-1)\n");
    sb.append("Pre-Depends: libaudit1 (>= 1:2.2.1), libc6 (>= 2.14), libpam0g (>= 0.99.7.1), libpam-runtime, libpam-modules (>= 1.1.8-1)\n");
    sb.append("Conflicts: amavisd-new (<< 2.3.3-8), backupninja (<< 0.9.3-5), echolot (<< 2.1.8-4), gnunet (<< 0.7.0c-2), python-4suite (<< 0.99cvs20060405-1)\n");
    sb.append("Conffiles:\n");
    sb.append(" /etc/login.defs 2a8f6cd8e00f54df72dc345a23f9db20\n");
    sb.append(" /etc/pam.d/login 1fd6cb4d4267a68148ee9973510a9d3e\n");
    sb.append(" /etc/pam.d/su ce6dcfda3b190a27a455bb38a45ff34a\n");
    sb.append(" /etc/securetty d0124b1d2fb22d4ac9a91aa02ae6d6db\n");
    sb.append("Description: system login tools\n");
    sb.append(" These tools are required to be able to login and use your system. The\n");
    sb.append(" login program invokes your user shell and enables command execution. The\n");
    sb.append(" newgrp program is used to change your effective group ID (useful for\n");
    sb.append(" workgroup type situations). The su program allows changing your effective\n");
    sb.append(" user ID (useful being able to execute commands as another user).\n");
    sb.append("Homepage: https://github.com/shadow-maint/shadow\n");
    sb.append("Original-Maintainer: Shadow package maintainers <pkg-shadow-devel@lists.alioth.debian.org>\n");
    String pkgMgrVersionOutput = sb.toString();
    final String packageNameWithArch = "login:amd64";
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(null, "dpkg", Arrays.asList("-s", packageNameWithArch))).thenReturn(new ExecutableOutput(0, pkgMgrVersionOutput, ""));
    DpkgPkgDetailsResolver dpkgVersionResolver = new DpkgPkgDetailsResolver();
    DpkgPackageManagerResolver pkgMgr = new DpkgPackageManagerResolver(dpkgVersionResolver);
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().dpkg(), executableRunner, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("login", pkgs.get(0).getPackageName());
    assertEquals("1:4.5-1ubuntu1", pkgs.get(0).getPackageVersion());
    assertEquals("amd64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DpkgPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver) DpkgPkgDetailsResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)53 File (java.io.File)18 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)14 ArrayList (java.util.ArrayList)14 Extraction (com.synopsys.integration.detectable.extraction.Extraction)13 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)13 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)10 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)9 Executable (com.synopsys.integration.executable.Executable)9 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)8 Test (org.junit.jupiter.api.Test)7 NameVersion (com.synopsys.integration.util.NameVersion)6 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 HashMap (java.util.HashMap)5 List (java.util.List)5 StringUtils (org.apache.commons.lang3.StringUtils)5 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)4 IOException (java.io.IOException)4 Optional (java.util.Optional)4 Gson (com.google.gson.Gson)3