Search in sources :

Example 21 with ExecutableOutput

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();
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 22 with ExecutableOutput

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();
    }
}
Also used : Arrays(java.util.Arrays) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) PropertyAuthority(com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority) Optional(java.util.Optional) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DetectProperty(com.blackducksoftware.integration.hub.detect.configuration.DetectProperty) ArrayList(java.util.ArrayList) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 23 with ExecutableOutput

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;
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 24 with ExecutableOutput

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;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 25 with ExecutableOutput

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);
}
Also used : GradleInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) GradleReportParser(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser) ExternalIdFactory(com.synopsys.integration.hub.bdio.model.externalid.ExternalIdFactory) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) File(java.io.File) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)

Aggregations

ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)30 File (java.io.File)16 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)14 ArrayList (java.util.ArrayList)12 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)10 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)9 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)8 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)7 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 Test (org.junit.Test)6 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)4 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)4 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)3 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)3 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3