Search in sources :

Example 1 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable 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 2 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable 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 3 with Executable

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

the class PipenvExtractor method getProjectName.

private String getProjectName(final File directory, final String pythonExe, final File setupFile) throws ExecutableRunnerException {
    String projectName = detectConfiguration.getProperty(DetectProperty.DETECT_PIP_PROJECT_NAME, PropertyAuthority.None);
    if (StringUtils.isBlank(projectName) && setupFile != null && setupFile.exists()) {
        final Executable findProjectNameExecutable = new Executable(directory, pythonExe, Arrays.asList(setupFile.getAbsolutePath(), "--name"));
        final List<String> output = executableRunner.execute(findProjectNameExecutable).getStandardOutputAsList();
        projectName = output.get(output.size() - 1).replace('_', '-').trim();
    }
    return projectName;
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 4 with Executable

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

the class PipenvExtractor method getProjectVersionName.

private String getProjectVersionName(final File directory, final String pythonExe, final File setupFile) throws ExecutableRunnerException {
    String projectVersionName = detectConfiguration.getProperty(DetectProperty.DETECT_PIP_PROJECT_VERSION_NAME, PropertyAuthority.None);
    if (StringUtils.isBlank(projectVersionName) && setupFile != null && setupFile.exists()) {
        final Executable findProjectNameExecutable = new Executable(directory, pythonExe, Arrays.asList(setupFile.getAbsolutePath(), "--version"));
        final List<String> output = executableRunner.execute(findProjectNameExecutable).getStandardOutputAsList();
        projectVersionName = output.get(output.size() - 1).trim();
    }
    return projectVersionName;
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 5 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable 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)

Aggregations

Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)22 ArrayList (java.util.ArrayList)13 File (java.io.File)11 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)10 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)8 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)6 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)2 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)2 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)1