Search in sources :

Example 31 with DetectableException

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

the class DockerDetectable method extractable.

@Override
public DetectableResult extractable() throws DetectableException {
    // TODO: Can this be improved with a Requirements object? - jp
    PassedResultBuilder passedResultBuilder = new PassedResultBuilder();
    javaExe = javaResolver.resolveJava();
    if (javaExe == null) {
        return new ExecutableNotFoundDetectableResult("java");
    } else {
        passedResultBuilder.foundExecutable(javaExe);
    }
    try {
        dockerExe = dockerResolver.resolveDocker();
    } catch (Exception e) {
        dockerExe = null;
    }
    if (dockerExe == null) {
        if (dockerDetectableOptions.isDockerPathRequired()) {
            return new ExecutableNotFoundDetectableResult("docker");
        } else {
            logger.debug("Docker executable not found, but it has been configured as not-required; proceeding with execution of Docker tool. Running in air-gap mode will not work without a Docker executable.");
        }
    } else {
        passedResultBuilder.foundExecutable(dockerExe);
    }
    dockerInspectorInfo = dockerInspectorResolver.resolveDockerInspector();
    if (dockerInspectorInfo == null) {
        return new InspectorNotFoundDetectableResult("docker");
    } else {
        passedResultBuilder.foundInspector(dockerInspectorInfo.getDockerInspectorJar());
    }
    return passedResultBuilder.build();
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) PassedResultBuilder(com.synopsys.integration.detectable.detectable.PassedResultBuilder) IOException(java.io.IOException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) InspectorNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.InspectorNotFoundDetectableResult)

Example 32 with DetectableException

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

the class ConanCodeLocationGenerator method populateGraphUnderNode.

private void populateGraphUnderNode(ConanGraphNode curGraphNode, Map<String, ConanNode<String>> graphNodes) throws DetectableException {
    Set<String> dependencyRefs = new HashSet<>(curGraphNode.getConanNode().getRequiresRefs().orElse(new ArrayList<>(0)));
    dependencyTypeFilter.ifShouldInclude(ConanDependencyType.BUILD, curGraphNode.getConanNode().getBuildRequiresRefs(), dependencyRefs::addAll);
    for (String childRef : dependencyRefs) {
        ConanNode<String> childNode = graphNodes.get(childRef);
        if (childNode == null) {
            throw new DetectableException(String.format("%s requires non-existent node %s", curGraphNode.getConanNode().getRef(), childRef));
        }
        ConanGraphNode childGraphNode = new ConanGraphNode(childNode);
        populateGraphUnderNode(childGraphNode, graphNodes);
        curGraphNode.addChild(childGraphNode);
    }
}
Also used : ConanGraphNode(com.synopsys.integration.detectable.detectables.conan.graph.ConanGraphNode) ArrayList(java.util.ArrayList) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) HashSet(java.util.HashSet)

Example 33 with DetectableException

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

the class ConanCodeLocationGenerator method generateDependency.

@NotNull
private Dependency generateDependency(ExternalIdFactory externalIdFactory, ConanGraphNode graphNode) throws DetectableException {
    String depName = graphNode.getConanNode().getName().orElseThrow(() -> new DetectableException(String.format("Missing dependency name: %s", graphNode.getConanNode())));
    String fullVersion = ConanExternalIdVersionGenerator.generateExternalIdVersionString(graphNode.getConanNode(), preferLongFormExternalIds);
    ExternalId externalId = externalIdFactory.createNameVersionExternalId(conanForge, depName, fullVersion);
    logger.trace("Generated Dependency for {}/{} with externalID: {}", depName, fullVersion, externalId.getExternalIdPieces());
    return new Dependency(depName, graphNode.getConanNode().getVersion().orElseThrow(() -> new DetectableException(String.format("Missing dependency version: %s", graphNode.getConanNode()))), externalId);
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with DetectableException

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

the class ConanCliExtractor method extract.

public Extraction extract(File projectDir, ExecutableTarget conanExe) {
    toolVersionLogger.log(projectDir, conanExe);
    ExecutableOutput conanInfoOutput;
    try {
        conanInfoOutput = conanCommandRunner.runConanInfoCommand(projectDir, conanExe);
    } catch (Exception e) {
        logger.error(String.format("Exception thrown executing conan info command: %s", e.getMessage()));
        return new Extraction.Builder().exception(e).build();
    }
    if (!conanCommandRunner.wasSuccess(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command reported errors").build();
    }
    if (!conanCommandRunner.producedOutput(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command produced no output").build();
    }
    try {
        ConanDetectableResult result = conanInfoParser.generateCodeLocationFromConanInfoOutput(conanInfoOutput.getStandardOutput());
        return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
    } catch (DetectableException e) {
        return new Extraction.Builder().failure(e.getMessage()).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 35 with DetectableException

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

the class HaskellCabalLibraryJsonProtoParser method extractDependency.

private NameVersion extractDependency(List<AttributeItem> attributes) throws DetectableException {
    String dependencyName = null;
    String dependencyVersion = null;
    for (AttributeItem attributeItem : attributes) {
        if ("name".equals(attributeItem.getName())) {
            dependencyName = attributeItem.getStringValue();
        } else if ("version".equals(attributeItem.getName())) {
            dependencyVersion = attributeItem.getStringValue();
        }
        if (dependencyName != null && dependencyVersion != null) {
            return new NameVersion(dependencyName, dependencyVersion);
        }
    }
    throw new DetectableException(String.format("Dependency name/version not found in attribute list: %s", attributes));
}
Also used : AttributeItem(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.AttributeItem) NameVersion(com.synopsys.integration.util.NameVersion) 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