Search in sources :

Example 1 with ExecutableOutput

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

the class PearCliExtractor method extract.

public Extraction extract(final File directory, final File pearExe, final ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final ExecutableOutput pearListing = executableRunner.execute(workingDirectory, pearExe, "list");
        final ExecutableOutput pearDependencies = executableRunner.execute(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME);
        // TODO: Why is this done here?
        final File packageFile = detectFileFinder.findFile(directory, PACKAGE_XML_FILENAME);
        final PearParseResult result = pearParser.parse(packageFile, pearListing, pearDependencies);
        final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PEAR, result.name, result.version);
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PEAR, directory.toString(), id, result.dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).projectName(result.name).projectVersion(result.version).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 2 with ExecutableOutput

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

the class ExeNugetInspector method execute.

@Override
public ExecutableOutput execute(File workingDirectory, List<String> arguments) throws ExecutableRunnerException {
    final Executable hubNugetInspectorExecutable = new Executable(workingDirectory, inspectorExe, arguments);
    final ExecutableOutput executableOutput = executableRunner.execute(hubNugetInspectorExecutable);
    return executableOutput;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 3 with ExecutableOutput

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

the class PipenvExtractor method extract.

public Extraction extract(final File directory, final String pythonExe, final String pipenvExe, final File setupFile) {
    Extraction extraction;
    try {
        final String projectName = getProjectName(directory, pythonExe, setupFile);
        final String projectVersionName = getProjectVersionName(directory, pythonExe, setupFile);
        final PipParseResult result;
        final Executable pipenvRunPipFreeze = new Executable(directory, pipenvExe, Arrays.asList("run", "pip", "freeze"));
        final ExecutableOutput pipFreezeOutput = executableRunner.execute(pipenvRunPipFreeze);
        final Executable pipenvGraph = new Executable(directory, pipenvExe, Arrays.asList("graph", "--bare"));
        final ExecutableOutput graphOutput = executableRunner.execute(pipenvGraph);
        result = pipenvTreeParser.parse(projectName, projectVersionName, pipFreezeOutput.getStandardOutputAsList(), graphOutput.getStandardOutputAsList(), directory.toString());
        if (result != null) {
            extraction = new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
        } else {
            extraction = new Extraction.Builder().failure("Pipenv graph could not successfully be parsed").build();
        }
    } catch (final Exception e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    return extraction;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 4 with ExecutableOutput

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

the class NpmCliExtractor method extract.

public Extraction extract(final File directory, final String npmExe, final ExtractionId extractionId) {
    final boolean includeDevDeps = detectConfiguration.getBooleanProperty(DetectProperty.DETECT_NPM_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None);
    final List<String> exeArgs = new ArrayList<>();
    exeArgs.add("ls");
    exeArgs.add("-json");
    if (!includeDevDeps) {
        exeArgs.add("-prod");
    }
    final String additionalArguments = detectConfiguration.getProperty(DetectProperty.DETECT_NPM_ARGUMENTS, PropertyAuthority.None);
    if (StringUtils.isNotBlank(additionalArguments)) {
        exeArgs.addAll(Arrays.asList(additionalArguments.split(" ")));
    }
    final Executable npmLsExe = new Executable(directory, npmExe, exeArgs);
    ExecutableOutput executableOutput;
    try {
        executableOutput = executableRunner.execute(npmLsExe);
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
    final String standardOutput = executableOutput.getStandardOutput();
    final String errorOutput = executableOutput.getErrorOutput();
    if (StringUtils.isNotBlank(errorOutput)) {
        logger.error("Error when running npm ls -json command");
        logger.error(errorOutput);
        return new Extraction.Builder().failure("Npm wrote to stderr while running npm ls.").build();
    } else if (StringUtils.isNotBlank(standardOutput)) {
        logger.debug("Parsing npm ls file.");
        logger.debug(standardOutput);
        try {
            final NpmParseResult result = npmCliParser.generateCodeLocation(directory.getCanonicalPath(), standardOutput);
            return new Extraction.Builder().success(result.codeLocation).projectName(result.projectName).projectVersion(result.projectVersion).build();
        } catch (final IOException e) {
            return new Extraction.Builder().exception(e).build();
        }
    } else {
        logger.error("Nothing returned from npm ls -json command");
        return new Extraction.Builder().failure("Npm returned error after running npm ls.").build();
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ArrayList(java.util.ArrayList) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) IOException(java.io.IOException) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) IOException(java.io.IOException)

Example 5 with ExecutableOutput

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

the class BazelExecutableFinder method findBazel.

public String findBazel(final DetectorEnvironment environment) {
    final boolean resolvedPreviously = isAlreadyFound(CacheableExecutableType.BAZEL);
    String resolvedBazel = null;
    try {
        final File bazelExeFile = getExecutable(CacheableExecutableType.BAZEL);
        if (bazelExeFile == null) {
            logger.debug("Unable to locate Bazel executable");
            return null;
        }
        resolvedBazel = bazelExeFile.getAbsolutePath();
    } catch (DetectorException e) {
        logger.debug(String.format("Unable to locate Bazel executable: %s", e.getMessage()));
        return null;
    }
    if (!resolvedPreviously) {
        final ExecutableOutput bazelQueryDepsRecursiveOutput;
        try {
            bazelQueryDepsRecursiveOutput = executableRunner.executeQuietly(environment.getDirectory(), resolvedBazel, BAZEL_VERSION_SUBCOMMAND);
            int returnCode = bazelQueryDepsRecursiveOutput.getReturnCode();
            logger.trace(String.format("Bazel version returned %d; output: %s", returnCode, bazelQueryDepsRecursiveOutput.getStandardOutput()));
        } catch (ExecutableRunnerException e) {
            logger.debug(String.format("Bazel version threw exception: %s", e.getMessage()));
            resolvedBazel = null;
        }
    }
    return resolvedBazel;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) File(java.io.File) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

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