use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.
the class ProjectInspectorExtractor method extract.
public Extraction extract(ProjectInspectorOptions projectInspectorOptions, List<String> extra, File targetDirectory, File outputDirectory, ExecutableTarget inspector) throws ExecutableFailedException {
File outputFile = new File(outputDirectory, "inspection.json");
List<String> arguments = new LinkedList<>();
arguments.add("inspect");
arguments.add("--dir");
arguments.add(targetDirectory.toString());
arguments.add("--output-file");
arguments.add(outputFile.toString());
arguments.addAll(extra);
Optional.ofNullable(projectInspectorOptions.getAdditionalArguments()).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> arguments.addAll(Arrays.asList(additionalArguments)));
executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(targetDirectory, inspector, arguments));
try {
String outputContents = FileUtils.readFileToString(outputFile, StandardCharsets.UTF_8);
List<CodeLocation> codeLocations = projectInspectorParser.parse(outputContents);
return new Extraction.Builder().success(codeLocations).build();
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException 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.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.
the class ExtractionEvaluatorTest method createEvaluationMocks.
private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractionExists, boolean throwException) throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
Detectable detectable = Mockito.mock(Detectable.class);
DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
Mockito.when(detectorEvaluation.getExtractionEnvironment()).thenReturn(extractionEnvironment);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
Mockito.when(detectorEvaluation.isExtractable()).thenReturn(true);
List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
Predicate<DetectorRule> rulePredicate = it -> true;
Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
if (throwException) {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenThrow(new RuntimeException("JUnit expected exception"));
} else {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenReturn(new Extraction.Builder().success().build());
}
return detectorEvaluation;
}
use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.
the class SbtPluginFinder method listPlugins.
private List<String> listPlugins(File directory, ExecutableTarget sbt, @Nullable String sbtCommandAdditionalArguments) throws DetectableException {
try {
List<String> args = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "plugins");
ExecutableOutput output = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, sbt, args));
return output.getStandardOutputAsList();
} catch (ExecutableFailedException e) {
throw new DetectableException("Unable to list installed sbt plugins, detect requires a suitable sbt plugin is available to find dependency graphs.", e);
}
}
use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.
the class BitbakeExtractor method extract.
public Extraction extract(File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile) throws ExecutableFailedException, IOException {
toolVersionLogger.log(() -> bitbakeCommandRunner.runBitbakeVersion(sourceDirectory, bashExecutable, buildEnvironmentFile));
File buildDirectory = determineBuildDirectory(sourceDirectory, bashExecutable, buildEnvironmentFile);
BitbakeEnvironment bitbakeEnvironment = executeBitbakeForEnvironment(sourceDirectory, bashExecutable, buildEnvironmentFile);
ShowRecipesResults showRecipesResults = executeBitbakeForRecipeLayerCatalog(sourceDirectory, bashExecutable, buildEnvironmentFile);
List<CodeLocation> codeLocations = packageNames.stream().map(targetPackage -> generateCodeLocationForTargetPackage(targetPackage, sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, showRecipesResults, bitbakeEnvironment)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (codeLocations.isEmpty()) {
return Extraction.failure("No Code Locations were generated during extraction");
} else {
return Extraction.success(codeLocations);
}
}
Aggregations