Search in sources :

Example 11 with DetectableException

use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.

the class ArtifactoryGradleInspectorResolver method resolveGradleInspector.

@Override
public File resolveGradleInspector() throws DetectableException {
    if (!hasResolvedInspector) {
        hasResolvedInspector = true;
        try {
            Optional<File> airGapPath = airGapInspectorPaths.getGradleInspectorAirGapFile();
            File generatedGradleScriptFile = directoryManager.getSharedFile(GRADLE_DIR_NAME, GENERATED_GRADLE_SCRIPT_NAME);
            GradleInspectorScriptCreator gradleInspectorScriptCreator = new GradleInspectorScriptCreator(configuration);
            if (airGapPath.isPresent()) {
                generatedGradleScriptPath = gradleInspectorScriptCreator.createOfflineGradleInspector(generatedGradleScriptFile, gradleInspectorScriptOptions, airGapPath.get().getCanonicalPath());
            } else {
                generatedGradleScriptPath = gradleInspectorScriptCreator.createOnlineGradleInspector(generatedGradleScriptFile, gradleInspectorScriptOptions);
            }
        } catch (Exception e) {
            throw new DetectableException(e);
        }
        if (generatedGradleScriptPath == null) {
            throw new DetectableException("Unable to initialize the gradle inspector.");
        } else {
            logger.trace(String.format("Derived generated gradle script path: %s", generatedGradleScriptPath));
        }
    } else {
        logger.debug("Already attempted to resolve the gradle inspector script, will not attempt again.");
    }
    if (generatedGradleScriptPath == null) {
        throw new DetectableException("Unable to find or create the gradle inspector script.");
    }
    return generatedGradleScriptPath;
}
Also used : GradleInspectorScriptCreator(com.synopsys.integration.detectable.detectables.gradle.inspection.inspector.GradleInspectorScriptCreator) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 12 with DetectableException

use of com.synopsys.integration.detectable.detectable.exception.DetectableException 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 13 with DetectableException

use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.

the class NugetInspectorExecutableLocator method findExecutable.

@Nullable
public File findExecutable(File extractedZip, String executableName) throws DetectableException {
    logger.debug("Looking for '" + executableName + "' in " + extractedZip.toString());
    File executable = new File(extractedZip, executableName);
    if (executable.exists()) {
        logger.debug("Found it: " + executable);
        if (!executable.canExecute() && !executable.setExecutable(true)) {
            throw new DetectableException("Unable to set project inspector to executable: " + executable);
        }
        return executable;
    } else {
        logger.debug("Could not find executable: " + executable);
        return null;
    }
}
Also used : File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with DetectableException

use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.

the class ConanCodeLocationGenerator method generateCodeLocationFromNodeMap.

@NotNull
public ConanDetectableResult generateCodeLocationFromNodeMap(ExternalIdFactory externalIdFactory, Map<String, ConanNode<String>> nodes) throws DetectableException {
    logger.debug("Generating code location from {} dependencies", nodes.keySet().size());
    Optional<ConanNode<String>> rootNode = getRoot(nodes.values());
    if (!rootNode.isPresent()) {
        throw new DetectableException("No root node found");
    }
    ConanGraphNode rootGraphNode = new ConanGraphNode(rootNode.get());
    populateGraphUnderNode(rootGraphNode, nodes);
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    CodeLocation codeLocation = generateCodeLocationFromConanGraph(externalIdFactory, dependencyGraph, rootGraphNode);
    return new ConanDetectableResult(rootGraphNode.getConanNode().getName().orElse(null), rootGraphNode.getConanNode().getVersion().orElse(null), codeLocation);
}
Also used : ConanGraphNode(com.synopsys.integration.detectable.detectables.conan.graph.ConanGraphNode) ConanNode(com.synopsys.integration.detectable.detectables.conan.graph.ConanNode) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DetectableException

use of com.synopsys.integration.detectable.detectable.exception.DetectableException 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

DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)39 File (java.io.File)22 IOException (java.io.IOException)13 Extraction (com.synopsys.integration.detectable.extraction.Extraction)8 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)8 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)8 List (java.util.List)8 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)6 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)6 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)6 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)5 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)5 NameVersion (com.synopsys.integration.util.NameVersion)5 ArrayList (java.util.ArrayList)5 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4