Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version distance policy being evaluated despite not being configured #382

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public PolicyCondition.Subject supportedSubject() {
@Override
public List<PolicyConditionViolation> evaluate(final Policy policy, final Component component) {
final var violations = new ArrayList<PolicyConditionViolation>();
if (component.getPurl() == null) {
if (component.getPurl() == null || component.getVersion() == null) {
return violations;
}

final List<PolicyCondition> conditions = super.extractSupportedConditions(policy);
if (conditions.isEmpty()) {
return violations;
}

Expand All @@ -83,9 +88,18 @@ public List<PolicyConditionViolation> evaluate(final Policy policy, final Compon
return violations;
}

final var versionDistance = VersionDistance.getVersionDistance(component.getVersion(),metaComponent.getLatestVersion());
final VersionDistance versionDistance;
try {
versionDistance = VersionDistance.getVersionDistance(component.getVersion(), metaComponent.getLatestVersion());
} catch (RuntimeException e) {
LOGGER.warn("""
Failed to compute version distance for component %s (UUID: %s), \
between component version %s and latest version %s; Skipping\
""".formatted(component, component.getUuid(), component.getVersion(), metaComponent.getLatestVersion()), e);
return violations;
}

for (final PolicyCondition condition : super.extractSupportedConditions(policy)) {
for (final PolicyCondition condition : conditions) {
if (isDirectDependency(component) && evaluate(condition, versionDistance)) {
violations.add(new PolicyConditionViolation(condition, component));
}
Expand Down