use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class DpkgPackageManager method getPackageVersion.
private Optional<String> getPackageVersion(final ExecutableRunner executableRunner, File workingDirectory, final String packageName) {
try {
final ExecutableOutput packageStatusOutput = executableRunner.executeQuietly(workingDirectory, PKG_MGR_NAME, GET_PKG_INFO_OPTION, packageName);
logger.debug(String.format("packageStatusOutput: %s", packageStatusOutput));
return getPackageVersionFromStatusOutput(packageName, packageStatusOutput.getStandardOutput());
} catch (final ExecutableRunnerException e) {
logger.error(String.format("Error executing %s to get package info: %s", PKG_MGR_NAME, e.getMessage()));
}
return Optional.empty();
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class MavenCliExtractor method extract.
public Extraction extract(final File directory, final String mavenExe) {
try {
String mavenCommand = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_BUILD_COMMAND, PropertyAuthority.None);
if (StringUtils.isNotBlank(mavenCommand)) {
mavenCommand = mavenCommand.replace("dependency:tree", "");
if (StringUtils.isNotBlank(mavenCommand)) {
mavenCommand = mavenCommand.trim();
}
}
final List<String> arguments = new ArrayList<>();
if (StringUtils.isNotBlank(mavenCommand)) {
arguments.addAll(Arrays.asList(mavenCommand.split(" ")));
}
arguments.add("dependency:tree");
final Executable mvnExecutable = new Executable(directory, mavenExe, arguments);
final ExecutableOutput mvnOutput = executableRunner.execute(mvnExecutable);
if (mvnOutput.getReturnCode() == 0) {
final String mavenScope = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_SCOPE, PropertyAuthority.None);
final String excludedModules = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_EXCLUDED_MODULES, PropertyAuthority.None);
final String includedModules = detectConfiguration.getProperty(DetectProperty.DETECT_MAVEN_INCLUDED_MODULES, PropertyAuthority.None);
final List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mvnOutput.getStandardOutput(), mavenScope, excludedModules, includedModules);
final List<DetectCodeLocation> codeLocations = mavenResults.stream().map(it -> it.codeLocation).collect(Collectors.toList());
final Optional<MavenParseResult> firstWithName = mavenResults.stream().filter(it -> StringUtils.isNoneBlank(it.projectName)).findFirst();
final Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
if (firstWithName.isPresent()) {
builder.projectName(firstWithName.get().projectName);
builder.projectVersion(firstWithName.get().projectVersion);
}
return builder.build();
} else {
final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", arguments), mvnOutput.getReturnCode()));
return builder.build();
}
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class ClangLinuxPackageManager method getPackages.
public List<PackageDetails> getPackages(File workingDirectory, final ExecutableRunner executableRunner, final Set<File> unManagedDependencyFiles, final DependencyFileDetails dependencyFile) {
final List<PackageDetails> dependencyDetailsList = new ArrayList<>(3);
try {
final List<String> fileSpecificGetOwnerArgs = new ArrayList<>(pkgMgrGetOwnerCmdArgs);
fileSpecificGetOwnerArgs.add(dependencyFile.getFile().getAbsolutePath());
final ExecutableOutput queryPackageOutput = executableRunner.executeQuietly(workingDirectory, pkgMgrCmdString, fileSpecificGetOwnerArgs);
logger.debug(String.format("queryPackageOutput: %s", queryPackageOutput));
this.addToPackageList(executableRunner, workingDirectory, dependencyDetailsList, queryPackageOutput.getStandardOutput());
return dependencyDetailsList;
} catch (final ExecutableRunnerException e) {
logger.error(String.format("Error executing %s: %s", pkgMgrCmdString, e.getMessage()));
if (!dependencyFile.isInBuildDir()) {
logger.debug(String.format("%s is not managed by %s", dependencyFile.getFile().getAbsolutePath(), pkgMgrCmdString));
unManagedDependencyFiles.add(dependencyFile.getFile());
} else {
logger.debug(String.format("%s is not managed by %s, but it's in the source.dir", dependencyFile.getFile().getAbsolutePath(), pkgMgrCmdString));
}
return dependencyDetailsList;
}
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class ClangLinuxPackageManager method applies.
public boolean applies(File workingDirectory, final ExecutableRunner executor) {
try {
final ExecutableOutput versionOutput = executor.execute(workingDirectory, getPkgMgrName(), getCheckPresenceCommandArgs());
logger.debug(String.format("packageStatusOutput: %s", versionOutput.getStandardOutput()));
if (versionOutput.getStandardOutput().contains(getCheckPresenceCommandOutputExpectedText())) {
logger.info(String.format("Found package manager %s", 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", getPkgMgrName(), getCheckPresenceCommandArgs(), getPkgMgrName(), versionOutput));
} catch (final ExecutableRunnerException e) {
logger.debug(String.format("Error executing %s %s; concluding that the %s package manager is not present. The error: %s", getPkgMgrName(), getCheckPresenceCommandArgs(), getPkgMgrName(), e.getMessage()));
return false;
}
return false;
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class GradleExtractionDebugger method debug.
public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) throws ExecutableRunnerException {
String id = extraction.extractionIdentifier;
ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
Mockito.when(executableRunner.execute(Mockito.any())).thenReturn(new ExecutableOutput("", ""));
DetectFileFinder detectFileFinder = new DetectFileFinder();
File mockSourceFile = Mockito.mock(File.class);
File outputDirectory = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
GradleInspectorExtractor gradleInspectorExtractor = new GradleInspectorExtractor(executableRunner, detectFileFinder, new GradleReportParser(new ExternalIdFactory()), detectConfiguration);
Extraction extractionResult = gradleInspectorExtractor.extract(mockSourceFile, "", "", outputDirectory);
}
Aggregations