use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extract.
public Extraction extract(final File directory) {
try {
final String included = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_INCLUDED_CONFIGURATIONS, PropertyAuthority.None);
final String excluded = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_EXCLUDED_CONFIGURATIONS, PropertyAuthority.None);
final int depth = detectConfiguration.getIntegerProperty(DetectProperty.DETECT_SBT_REPORT_DEPTH, PropertyAuthority.None);
final SbtPackager packager = new SbtPackager(externalIdFactory, detectFileFinder);
final SbtProject project = packager.extractProject(directory.getAbsolutePath(), depth, included, excluded);
final List<DetectCodeLocation> codeLocations = new ArrayList<>();
String projectName = null;
String projectVersion = null;
for (final SbtDependencyModule module : project.modules) {
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.SBT, directory.toString(), project.projectExternalId, module.graph).build();
if (projectName == null) {
projectName = project.projectName;
projectVersion = project.projectVersion;
}
codeLocations.add(codeLocation);
}
if (codeLocations.size() > 0) {
return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Unable to find any dependency information.");
return new Extraction.Builder().failure("Unable to find any dependency information.").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 YarnLockExtractor method extract.
public Extraction extract(final File directory, final File yarnlock, final String yarnExe) {
try {
final List<String> yarnLockText = Files.readAllLines(yarnlock.toPath(), StandardCharsets.UTF_8);
final List<String> exeArgs = Stream.of("list", "--emoji", "false").collect(Collectors.toCollection(ArrayList::new));
if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_YARN_PROD_ONLY, PropertyAuthority.None)) {
exeArgs.add("--prod");
}
final Executable yarnListExe = new Executable(directory, yarnExe, exeArgs);
final ExecutableOutput executableOutput = executableRunner.execute(yarnListExe);
if (executableOutput.getReturnCode() != 0) {
final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", exeArgs), executableOutput.getReturnCode()));
return builder.build();
}
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(yarnLockText, executableOutput.getStandardOutputAsList());
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.NPM, directory.getCanonicalPath());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.YARN, directory.getCanonicalPath(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).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 ToolRunner method run.
public void run(final RunResult runResult) throws DetectorException {
logger.info(String.format("Checking if %s applies.", toolDetector.getToolEnum().toString()));
DetectorResult applicableResult = toolDetector.applicable();
if (applicableResult.getPassed()) {
logger.info(String.format("Checking if %s is extractable.", toolDetector.getToolEnum().toString()));
DetectorResult extractableResult = toolDetector.extractable();
if (extractableResult.getPassed()) {
logger.info(String.format("Performing the %s extraction.", toolDetector.getToolEnum().toString()));
Extraction extractionResults = toolDetector.extract();
if (extractionResults.result != Extraction.ExtractionResultType.SUCCESS) {
logger.error(String.format("%s extraction failed: %s", toolDetector.getToolEnum().toString(), extractionResults.description));
}
publishExtractionResults(eventSystem, runResult, extractionResults);
} else {
publishNotExtractableResults(eventSystem, extractableResult, toolDetector.getToolEnum().toString());
}
} else {
logger.info(String.format("%s was not applicable, will not actually run %s tool.", toolDetector.getToolEnum().toString(), toolDetector.getToolEnum().toString()));
logger.info(applicableResult.toDescription());
}
}
use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.
the class GemlockExtractor method extract.
public Extraction extract(final File directory, final File gemlock) {
try {
final List<String> gemlockText = Files.readAllLines(gemlock.toPath(), StandardCharsets.UTF_8);
logger.debug(gemlockText.stream().collect(Collectors.joining("\n")));
final GemlockParser gemlockParser = new GemlockParser(externalIdFactory);
final DependencyGraph dependencyGraph = gemlockParser.parseProjectDependencies(gemlockText);
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.RUBYGEMS, directory.toString());
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.RUBYGEMS, directory.toString(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(codeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations