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

🐛 Use "and" to chain some conditions for more accuracy #113

Merged
merged 1 commit into from
Feb 9, 2024
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
31 changes: 30 additions & 1 deletion pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func ConvertWindupRulesetToAnalyzer(ruleset windup.Ruleset) []map[string]interfa
if len(when) == 1 {
rule["when"] = when[0]
} else if len(when) > 1 {
rule["when"] = map[string]interface{}{"or": when}
if canUseAndToChain(when) {
rule["when"] = map[string]interface{}{"and": when}
} else {
rule["when"] = map[string]interface{}{"or": when}
}
} else {
continue
}
Expand Down Expand Up @@ -983,3 +987,28 @@ func escapeParens(s string) string {
s = strings.Replace(s, ")", "\\)", -1)
return s
}

// canUseAndToChain when converting chained conditions, we check if they can
// be ANDed...it improves accuracy: https://github.com/konveyor/rulesets/issues/41
// we can only do this for builtin conditions reliably
func canUseAndToChain(when []map[string]interface{}) bool {
canDetermine := true
fromUsed := false
asUsed := false
for _, cond := range when {
for key := range cond {
// if any one condition is java, we can't make this an AND
if strings.HasPrefix(key, "java") {
canDetermine = false
break
}
if key == "from" {
fromUsed = true
}
if key == "as" {
asUsed = true
}
}
}
return canDetermine && fromUsed && asUsed
}
Loading