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;
}
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);
}
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;
}
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();
}
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());
}
Aggregations