use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method testExtractionException.
@Test
public void testExtractionException() throws DetectableException, ExecutableFailedException {
Extraction extraction = createExceptionExtraction();
DetectableResult extractionResult = new PassedDetectableResult();
String projectBomTool = DetectorType.GO_MOD.name();
DetectorToolResult result = executeToolTest(extraction, extractionResult, projectBomTool);
assertFalse(result.getApplicableDetectorTypes().isEmpty());
assertTrue(result.getBomToolCodeLocations().isEmpty());
assertFalse(result.getBomToolProjectNameVersion().isPresent());
assertTrue(result.getCodeLocationMap().isEmpty());
assertTrue(result.getFailedDetectorTypes().isEmpty());
assertTrue(result.getRootDetectorEvaluationTree().isPresent());
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class NpmCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget npmExe, @Nullable String npmArguments, File packageJsonFile) {
toolVersionLogger.log(directory, npmExe);
PackageJson packageJson;
try {
packageJson = parsePackageJson(packageJsonFile);
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
List<String> exeArgs = new ArrayList<>();
exeArgs.add("ls");
exeArgs.add("-json");
Optional.ofNullable(npmArguments).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> exeArgs.addAll(Arrays.asList(additionalArguments)));
ExecutableOutput npmLsOutput;
try {
npmLsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, npmExe, exeArgs));
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
String standardOutput = npmLsOutput.getStandardOutput();
String errorOutput = npmLsOutput.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);
NpmPackagerResult result = npmCliParser.generateCodeLocation(standardOutput, packageJson);
String projectName = result.getProjectName() != null ? result.getProjectName() : packageJson.name;
String projectVersion = result.getProjectVersion() != null ? result.getProjectVersion() : packageJson.version;
return new Extraction.Builder().success(result.getCodeLocation()).projectName(projectName).projectVersion(projectVersion).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.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class GoVendorExtractor method extract.
public Extraction extract(File vendorJsonFile) {
try {
GoVendorJsonParser vendorJsonParser = new GoVendorJsonParser(externalIdFactory);
String vendorJsonContents = FileUtils.readFileToString(vendorJsonFile, StandardCharsets.UTF_8);
logger.debug(vendorJsonContents);
DependencyGraph dependencyGraph = vendorJsonParser.parseVendorJson(gson, vendorJsonContents);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class MavenCliExtractor method extract.
// TODO: Limit 'extractors' to 'execute' and 'read', delegate all other work.
public Extraction extract(File directory, ExecutableTarget mavenExe, MavenCliExtractorOptions mavenCliExtractorOptions) throws ExecutableFailedException {
toolVersionLogger.log(directory, mavenExe);
List<String> commandArguments = commandParser.parseCommandString(mavenCliExtractorOptions.getMavenBuildCommand().orElse("")).stream().filter(arg -> !arg.equals("dependency:tree")).collect(Collectors.toList());
commandArguments.add("dependency:tree");
// Force maven to use a single thread to ensure the tree output is in the correct order.
commandArguments.add("-T1");
ExecutableOutput mvnExecutableResult = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, mavenExe, commandArguments));
List<String> mavenOutput = mvnExecutableResult.getStandardOutputAsList();
List<String> excludedScopes = mavenCliExtractorOptions.getMavenExcludedScopes();
List<String> includedScopes = mavenCliExtractorOptions.getMavenIncludedScopes();
List<String> excludedModules = mavenCliExtractorOptions.getMavenExcludedModules();
List<String> includedModules = mavenCliExtractorOptions.getMavenIncludedModules();
List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mavenOutput, excludedScopes, includedScopes, excludedModules, includedModules);
List<CodeLocation> codeLocations = Bds.of(mavenResults).map(MavenParseResult::getCodeLocation).toList();
Optional<MavenParseResult> firstWithName = Bds.of(mavenResults).firstFiltered(it -> StringUtils.isNotBlank(it.getProjectName()));
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
if (firstWithName.isPresent()) {
builder.projectName(firstWithName.get().getProjectName());
builder.projectVersion(firstWithName.get().getProjectVersion());
}
return builder.build();
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class GoVndrExtractor method extract.
public Extraction extract(File vndrConfig) {
try {
VndrParser vndrParser = new VndrParser(externalIdFactory);
List<String> vendorConfContents = Files.readAllLines(vndrConfig.toPath(), StandardCharsets.UTF_8);
logger.debug(String.join("\n", vendorConfContents));
DependencyGraph dependencyGraph = vndrParser.parseVendorConf(vendorConfContents);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations