use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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();
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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;
}
use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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();
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.
the class PipInspectorExtractor method extract.
public Extraction extract(final File directory, final String pythonExe, final File pipInspector, final File setupFile, final String requirementFilePath) {
Extraction extractionResult;
try {
final String projectName = getProjectName(directory, pythonExe, setupFile);
final Optional<PipParseResult> result;
final List<String> inspectorOutput = runInspector(directory, pythonExe, pipInspector, projectName, requirementFilePath);
result = pipInspectorTreeParser.parse(inspectorOutput, directory.toString());
if (!result.isPresent()) {
extractionResult = new Extraction.Builder().failure("The Pip Inspector tree parser failed to produce output").build();
} else {
extractionResult = new Extraction.Builder().success(result.get().getCodeLocation()).projectName(result.get().getProjectName()).projectVersion(result.get().getProjectVersion()).build();
}
} catch (final Exception e) {
extractionResult = new Extraction.Builder().exception(e).build();
}
return extractionResult;
}
use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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();
}
Aggregations