Search in sources :

Example 6 with ExecutableFailedException

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();
    }
}
Also used : Arrays(java.util.Arrays) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) LinkedList(java.util.LinkedList) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList)

Example 7 with ExecutableFailedException

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();
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) List(java.util.List) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Bds(com.synopsys.integration.common.util.Bds) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 8 with ExecutableFailedException

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;
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) CycleDetectedException(com.synopsys.integration.detectable.util.CycleDetectedException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Predicate(java.util.function.Predicate) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 9 with ExecutableFailedException

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);
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 10 with ExecutableFailedException

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);
    }
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IntegrationException(com.synopsys.integration.exception.IntegrationException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BitbakeDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) PwdOutputParser(com.synopsys.integration.detectable.detectables.bitbake.parse.PwdOutputParser) Charset(java.nio.charset.Charset) Map(java.util.Map) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Logger(org.slf4j.Logger) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) BitbakeGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeGraphTransformer) GraphParser(com.paypal.digraph.parser.GraphParser) BuildFileFinder(com.synopsys.integration.detectable.detectables.bitbake.collect.BuildFileFinder) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BitbakeEnvironmentParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeEnvironmentParser) BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) BitbakeCommandRunner(com.synopsys.integration.detectable.detectables.bitbake.collect.BitbakeCommandRunner) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) Optional(java.util.Optional) BitbakeRecipesParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeRecipesParser) LicenseManifestParser(com.synopsys.integration.detectable.detectables.bitbake.parse.LicenseManifestParser) InputStream(java.io.InputStream) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) File(java.io.File)

Aggregations

ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)10 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)7 Extraction (com.synopsys.integration.detectable.extraction.Extraction)7 File (java.io.File)7 IOException (java.io.IOException)7 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 List (java.util.List)5 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)4 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 GraphParser (com.paypal.digraph.parser.GraphParser)2 MissingExternalIdException (com.synopsys.integration.bdio.graph.builder.MissingExternalIdException)2 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)2 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)2 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)2 BitbakeGraph (com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)2 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)2 CycleDetectedException (com.synopsys.integration.detectable.util.CycleDetectedException)2 ToolVersionLogger (com.synopsys.integration.detectable.util.ToolVersionLogger)2