Search in sources :

Example 1 with AttributeItem

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.AttributeItem 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)

Example 2 with AttributeItem

use of com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.AttributeItem in project synopsys-detect by blackducksoftware.

the class HaskellCabalLibraryJsonProtoParser method extractAddDependencies.

private void extractAddDependencies(String jsonProtoString, List<NameVersion> dependencies, ResultItem result) throws DetectableException {
    if (result == null || result.getTarget() == null) {
        throw new DetectableException(String.format("Unable to parse target from result inJSON proto string: %s", jsonProtoString));
    }
    Target target = result.getTarget();
    if ("RULE".equals(target.getType())) {
        if (target.getRule() == null || target.getRule().getAttribute() == null) {
            throw new DetectableException(String.format("Unable to parse attributes from rule inJSON proto string: %s", jsonProtoString));
        }
        List<AttributeItem> attributes = target.getRule().getAttribute();
        NameVersion dependency = extractDependency(attributes);
        logger.debug("Adding dependency {}/{}}", dependency.getName(), dependency.getVersion());
        dependencies.add(dependency);
    }
}
Also used : Target(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.Target) 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)2 AttributeItem (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.AttributeItem)2 NameVersion (com.synopsys.integration.util.NameVersion)2 Target (com.synopsys.integration.detectable.detectables.bazel.pipeline.step.model.Target)1