Search in sources :

Example 1 with ExecutableFailedException

use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.

the class GoModCliExtractor method extract.

public Extraction extract(File directory, ExecutableTarget goExe) throws ExecutableFailedException, JsonSyntaxException, DetectableException {
    List<GoListModule> goListModules = listModules(directory, goExe);
    List<GoListAllData> goListAllModules = listAllModules(directory, goExe);
    List<GoGraphRelationship> goGraphRelationships = listGraphRelationships(directory, goExe);
    Set<String> excludedModules = listExcludedModules(directory, goExe);
    GoRelationshipManager goRelationshipManager = new GoRelationshipManager(goGraphRelationships, excludedModules);
    GoModDependencyManager goModDependencyManager = new GoModDependencyManager(goListAllModules, externalIdFactory);
    List<CodeLocation> codeLocations = goListModules.stream().map(goListModule -> goModGraphGenerator.generateGraph(goListModule, goRelationshipManager, goModDependencyManager)).collect(Collectors.toList());
    // No project info - hoping git can help with that.
    return new Extraction.Builder().success(codeLocations).build();
}
Also used : GoListParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoListParser) JsonSyntaxException(com.google.gson.JsonSyntaxException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) GoModGraphGenerator(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModGraphGenerator) Collectors(java.util.stream.Collectors) GoVersionParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoVersionParser) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) File(java.io.File) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) GoGraphParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoGraphParser) Collections(java.util.Collections) GoModWhyParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoModWhyParser) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)

Example 2 with ExecutableFailedException

use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.

the class DetectableTool method extract.

public DetectableToolResult extract() {
    // TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
    DetectableResult extractable;
    try {
        extractable = detectable.extractable();
    } catch (DetectableException e) {
        extractable = new ExceptionDetectableResult(e);
    }
    if (!extractable.getPassed()) {
        logger.error(String.format("Was not extractable: %s", extractable.toDescription()));
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", Arrays.asList(extractable.toDescription())));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_GENERAL_ERROR, extractable.toDescription());
        return DetectableToolResult.failed(extractable);
    }
    logger.debug("Extractable passed.");
    ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.createExtractionEnvironment(name);
    Extraction extraction;
    try {
        extraction = detectable.extract(extractionEnvironment);
    } catch (ExecutableFailedException | ExecutableRunnerException | JsonSyntaxException | IOException | CycleDetectedException | DetectableException | MissingExternalIdException | ParserConfigurationException | SAXException e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    if (!extraction.isSuccess()) {
        logger.error("Extraction was not success.");
        List<String> errorMessages = collectErrorMessages(extraction);
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", errorMessages));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extraction.getDescription()));
        return DetectableToolResult.failed();
    } else {
        logger.debug("Extraction success.");
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.SUCCESS));
    }
    Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap = codeLocationConverter.toDetectCodeLocation(sourcePath, extraction, sourcePath, name);
    List<DetectCodeLocation> detectCodeLocations = new ArrayList<>(detectCodeLocationMap.values());
    DockerTargetData dockerTargetData = DockerTargetData.fromExtraction(extraction);
    DetectToolProjectInfo projectInfo = null;
    if (StringUtils.isNotBlank(extraction.getProjectName()) || StringUtils.isNotBlank(extraction.getProjectVersion())) {
        NameVersion nameVersion = new NameVersion(extraction.getProjectName(), extraction.getProjectVersion());
        projectInfo = new DetectToolProjectInfo(detectTool, nameVersion);
    }
    logger.debug("Tool finished.");
    return DetectableToolResult.success(detectCodeLocations, projectInfo, dockerTargetData);
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) NameVersion(com.synopsys.integration.util.NameVersion) CycleDetectedException(com.synopsys.integration.detectable.util.CycleDetectedException) ArrayList(java.util.ArrayList) SAXException(org.xml.sax.SAXException) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DockerTargetData(com.synopsys.integration.detect.lifecycle.run.data.DockerTargetData) Status(com.synopsys.integration.detect.workflow.status.Status) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) JsonSyntaxException(com.google.gson.JsonSyntaxException) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) DetectToolProjectInfo(com.synopsys.integration.detect.workflow.project.DetectToolProjectInfo) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 3 with ExecutableFailedException

use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.

the class BitbakeExtractor method generateCodeLocationForTargetPackage.

private Optional<CodeLocation> generateCodeLocationForTargetPackage(String targetPackage, File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile, File buildDirectory, ShowRecipesResults showRecipesResults, BitbakeEnvironment bitbakeEnvironment) {
    try {
        BitbakeGraph bitbakeGraph = generateBitbakeGraph(sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, targetPackage, showRecipesResults.getLayerNames());
        Map<String, String> imageRecipes = null;
        if (dependencyTypeFilter.shouldExclude(BitbakeDependencyType.BUILD)) {
            imageRecipes = readImageRecipes(buildDirectory, targetPackage, bitbakeEnvironment);
        }
        DependencyGraph dependencyGraph = bitbakeDependencyGraphTransformer.transform(bitbakeGraph, showRecipesResults.getRecipesWithLayers(), imageRecipes);
        return Optional.of(new CodeLocation(dependencyGraph));
    } catch (ExecutableFailedException | IntegrationException | IOException e) {
        logger.error("Failed to extract a Code Location while running Bitbake against package '{}': {}", targetPackage, e.getMessage());
        logger.debug(e.getMessage(), e);
        return Optional.empty();
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) IntegrationException(com.synopsys.integration.exception.IntegrationException) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)

Example 4 with ExecutableFailedException

use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.

the class BitbakeExtractor method determineBuildDirectory.

private File determineBuildDirectory(File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile) {
    File fallbackBuildDir = new File(sourceDirectory, DEFAULT_BUILD_DIR_NAME);
    File derivedBuildDirectory;
    try {
        List<String> pwdOutput = bitbakeCommandRunner.runPwdCommand(sourceDirectory, bashExecutable, buildEnvironmentFile);
        derivedBuildDirectory = pwdOutputParser.deriveBuildDirectory(pwdOutput);
    } catch (ExecutableFailedException | IOException e) {
        logger.warn("Unable to determine build directory location due to error: {}; ; using {} for build dir", e.getMessage(), fallbackBuildDir.getAbsolutePath());
        return fallbackBuildDir;
    }
    if (derivedBuildDirectory.isDirectory()) {
        logger.debug("Derived build dir: {}", derivedBuildDirectory.getAbsolutePath());
        return derivedBuildDirectory;
    } else {
        logger.warn("Derived build dir {} is not a directory; using {} for build dir", derivedBuildDirectory.getAbsolutePath(), fallbackBuildDir.getAbsolutePath());
        return fallbackBuildDir;
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) IOException(java.io.IOException) File(java.io.File)

Example 5 with ExecutableFailedException

use of com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException in project synopsys-detect by blackducksoftware.

the class SbtDotExtractor method extract.

public Extraction extract(File directory, ExecutableTarget sbt, String sbtCommandAdditionalArguments) {
    try {
        List<String> sbtArgs = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "dependencyDot");
        Executable dotExecutable = ExecutableUtils.createFromTarget(directory, sbt, sbtArgs);
        ExecutableOutput dotOutput = executableRunner.executeSuccessfully(dotExecutable);
        List<File> dotGraphs = sbtDotOutputParser.parseGeneratedGraphFiles(dotOutput.getStandardOutputAsList());
        Extraction.Builder extraction = new Extraction.Builder();
        for (File dotGraph : dotGraphs) {
            GraphParser graphParser = new GraphParser(FileUtils.openInputStream(dotGraph));
            Set<String> rootIDs = sbtRootNodeFinder.determineRootIDs(graphParser);
            // typically found in project-folder/target/<>.dot so .parent.parent == project folder
            File projectFolder = dotGraph.getParentFile().getParentFile();
            if (rootIDs.size() == 1) {
                String projectId = rootIDs.stream().findFirst().get();
                DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, projectId);
                Dependency projectDependency = graphNodeParser.nodeToDependency(projectId);
                extraction.codeLocations(new CodeLocation(graph, projectDependency.getExternalId(), projectFolder));
                if (projectFolder.equals(directory)) {
                    extraction.projectName(projectDependency.getName());
                    extraction.projectVersion(projectDependency.getVersion());
                }
            } else {
                logger.warn("Unable to determine which node was the project in an SBT graph: " + dotGraph.toString());
                logger.warn("This may mean you have extraneous dependencies and should consider removing them. The dependencies are: " + String.join(",", rootIDs));
                DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, rootIDs);
                extraction.codeLocations(new CodeLocation(graph, projectFolder));
            }
        }
        return extraction.success().build();
    } catch (IOException | DetectableException | ExecutableFailedException e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphParser(com.paypal.digraph.parser.GraphParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) IOException(java.io.IOException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

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