use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.
the class PipInspectorExtractor 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 (setupFile != null && setupFile.exists() && StringUtils.isBlank(projectName)) {
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;
}
use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.
the class DockerExtractor method importTars.
private void importTars(final File inspectorJar, final List<File> importTars, final File directory, final Map<String, String> environmentVariables, final File bashExe) {
try {
for (final File imageToImport : importTars) {
// The -c is a bash option, the following String is the command we want to run
final List<String> dockerImportArguments = Arrays.asList("-c", "docker load -i \"" + imageToImport.getCanonicalPath() + "\"");
final Executable dockerImportImageExecutable = new Executable(directory, environmentVariables, bashExe.toString(), dockerImportArguments);
executableRunner.execute(dockerImportImageExecutable);
}
} catch (final Exception e) {
logger.debug("Exception encountered when resolving paths for docker air gap, running in online mode instead");
logger.debug(e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.
the class DockerExtractor method executeDocker.
private Extraction executeDocker(File outputDirectory, final String imageArgument, final String imagePiece, final String dockerTarFilePath, final File directory, final File javaExe, final File bashExe, final DockerInspectorInfo dockerInspectorInfo) throws IOException, ExecutableRunnerException {
final File dockerPropertiesFile = new File(outputDirectory, "application.properties");
dockerProperties.populatePropertiesFile(dockerPropertiesFile, outputDirectory);
final Map<String, String> environmentVariables = new HashMap<>(0);
final List<String> dockerArguments = new ArrayList<>();
dockerArguments.add("-jar");
dockerArguments.add(dockerInspectorInfo.getDockerInspectorJar().getAbsolutePath());
dockerArguments.add("--spring.config.location");
dockerArguments.add("file:" + dockerPropertiesFile.getCanonicalPath());
dockerArguments.add(imageArgument);
if (dockerInspectorInfo.hasAirGapImageFiles()) {
importTars(dockerInspectorInfo.getDockerInspectorJar(), dockerInspectorInfo.getAirGapInspectorImageTarfiles(), outputDirectory, environmentVariables, bashExe);
}
final Executable dockerExecutable = new Executable(outputDirectory, environmentVariables, javaExe.getAbsolutePath(), dockerArguments);
executableRunner.execute(dockerExecutable);
final File producedTarFile = detectFileFinder.findFile(outputDirectory, TAR_FILENAME_PATTERN);
File scanFile = null;
if (null != producedTarFile && producedTarFile.isFile()) {
scanFile = producedTarFile;
} else {
logger.debug(String.format("No files found matching pattern [%s]. Expected docker-inspector to produce file in %s", TAR_FILENAME_PATTERN, outputDirectory.getCanonicalPath()));
if (StringUtils.isNotBlank(dockerTarFilePath)) {
final File dockerTarFile = new File(dockerTarFilePath);
if (dockerTarFile.isFile()) {
logger.debug(String.format("Will scan the provided Docker tar file %s", dockerTarFile.getCanonicalPath()));
scanFile = dockerTarFile;
}
}
}
Extraction.Builder extractionBuilder = findCodeLocations(outputDirectory, directory, imagePiece);
extractionBuilder.metaData(DOCKER_TAR_META_DATA_KEY, scanFile);
return extractionBuilder.build();
}
use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.
the class BitbakeExtractor method runBitbake.
private ExecutableOutput runBitbake(final File outputDirectory, final File buildEnvScript, final String bitbakeCommand, File bash) {
final List<String> arguments = new ArrayList<>();
arguments.add("-c");
arguments.add(". " + buildEnvScript + "; " + bitbakeCommand);
final Executable sourceExecutable = new Executable(outputDirectory, bash, arguments);
ExecutableOutput executableOutput = null;
try {
executableOutput = executableRunner.execute(sourceExecutable);
} catch (final ExecutableRunnerException e) {
logger.error(String.format("Failed executing command '%s'", sourceExecutable.getExecutableDescription()));
logger.debug(e.getMessage(), e);
}
return executableOutput;
}
use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.
the class CondaCliExtractor method extract.
public Extraction extract(final File directory, final File condaExe, ExtractionId extractionId) {
try {
File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
final List<String> condaListOptions = new ArrayList<>();
condaListOptions.add("list");
final String condaEnvironmentName = detectConfiguration.getProperty(DetectProperty.DETECT_CONDA_ENVIRONMENT_NAME, PropertyAuthority.None);
if (StringUtils.isNotBlank(condaEnvironmentName)) {
condaListOptions.add("-n");
condaListOptions.add(condaEnvironmentName);
}
condaListOptions.add("--json");
final Executable condaListExecutable = new Executable(directory, condaExe, condaListOptions);
final ExecutableOutput condaListOutput = executableRunner.execute(condaListExecutable);
final String listJsonText = condaListOutput.getStandardOutput();
final ExecutableOutput condaInfoOutput = executableRunner.execute(workingDirectory, condaExe, "info", "--json");
final String infoJsonText = condaInfoOutput.getStandardOutput();
final DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.ANACONDA, directory.toString());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CONDA, directory.toString(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations