From 48ad85cd8d2cc2e459bb6455aac57bcf994e9c4c Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 7 Feb 2024 12:35:57 +0100 Subject: [PATCH 1/3] Depend on our windup-rulesets fork, some fixes around conversion Signed-off-by: Juan Manuel Leflet Estrada --- Dockerfile | 2 +- pkg/conversion/convert.go | 60 +++++++++++++++++++--------------- pkg/conversion/convert_test.go | 25 ++++++++++++++ 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8236d8ea..9d1ad04a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN wget -qO /tmp/windup.zip $WINDUP \ && rm /tmp/windup.zip \ && ln -s /windup/tackle-cli-*/bin/windup-cli /usr/bin/windup-cli -RUN git clone https://github.com/windup/windup-rulesets.git -b 6.2.3.Final /windup-rulesets \ +RUN git clone https://github.com/jmle/windup-rulesets.git -b konveyor-tmp /windup-rulesets \ && git clone https://github.com/konveyor/example-applications /example-applications COPY --from=java-builder /usr/local/openjdk-11 /java-11-openjdk diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index 11d357f6..426e0c69 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -392,30 +392,7 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string if windupWhen.Javaclass != nil { for _, jc := range windupWhen.Javaclass { customVars = convertWhereToCustomVars(where, jc.References) - pattern := strings.Replace(substituteWhere(where, jc.References), "{*}", "*", -1) - pattern = strings.Replace(pattern, "(*)", "*", -1) - pattern = strings.Replace(pattern, ".*", "*", -1) - pattern = strings.Replace(pattern, `\`, "", -1) - // Make some .* regesx's more generic. - pattern = strings.Replace(pattern, `(.*)?.`, ".*", -1) - pattern = strings.Replace(pattern, `.[^.]+`, "*", -1) - pattern = strings.Replace(pattern, `[^.]+`, "*", -1) - pattern = strings.Replace(pattern, `[^.()]+`, "*", -1) - pattern = strings.Replace(pattern, `(.[^.]*)*`, "*", -1) - pattern = strings.Replace(pattern, `+[^.]*?`, "*", -1) - pattern = strings.Replace(pattern, `[*]`, `\[*\]`, -1) - pattern = strings.Replace(pattern, `([a-z]+.)`, `*`, -1) - // remove open paranthesis which will be otherwise interpreted as wildcards - pattern = regexp.MustCompile(`\(\*$`).ReplaceAllString(pattern, "*") - pattern = regexp.MustCompile(`\(\)`).ReplaceAllString(pattern, "*") - pattern = regexp.MustCompile(`\[\]`).ReplaceAllString(pattern, "*") - // cascade multiple dots and stars - pattern = regexp.MustCompile(`[\.]{2,}\*`).ReplaceAllString(pattern, ".*") - pattern = regexp.MustCompile(`[\*]{2,}`).ReplaceAllString(pattern, "*") - pattern = strings.Replace(pattern, ".(*)?*", ".*", -1) - // when there are wildcards in the middle of the pattern, make them .* - // see https://github.com/konveyor/analyzer-lsp/issues/481 - pattern = regexp.MustCompile(`([A-Za-z])\*([A-Za-z])`).ReplaceAllString(pattern, `$1.*$2`) + pattern := convertJavaPattern(where, jc.References) // when pattern ends with * and a location is not specified // we guess the location based on defined pattern if strings.HasSuffix(pattern, "*") && jc.Location == nil { @@ -634,10 +611,41 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string return conditions, customVars } +func convertJavaPattern(where map[string]string, references string) string { + pattern := substituteWhere(where, references) + pattern = strings.Replace(pattern, "((", "(", -1) + pattern = strings.Replace(pattern, "))", ")", -1) + pattern = strings.Replace(pattern, "{*}", "*", -1) + pattern = strings.Replace(pattern, "(*)", "*", -1) + pattern = strings.Replace(pattern, ".*", "*", -1) + pattern = strings.Replace(pattern, `\`, "", -1) + // Make some .* regesx's more generic. + pattern = strings.Replace(pattern, `(.*)?.`, ".*", -1) + pattern = strings.Replace(pattern, `.[^.]+`, "*", -1) + pattern = strings.Replace(pattern, `[^.]+`, "*", -1) + pattern = strings.Replace(pattern, `[^.()]+`, "*", -1) + pattern = strings.Replace(pattern, `(.[^.]*)*`, "*", -1) + pattern = strings.Replace(pattern, `+[^.]*?`, "*", -1) + pattern = strings.Replace(pattern, `[*]`, `\[*\]`, -1) + pattern = strings.Replace(pattern, `([a-z]+.)`, `*`, -1) + // remove open parenthesis which will be otherwise interpreted as wildcards + pattern = regexp.MustCompile(`\(\*$`).ReplaceAllString(pattern, "*") + pattern = regexp.MustCompile(`\(\)`).ReplaceAllString(pattern, "*") + pattern = regexp.MustCompile(`\[\]`).ReplaceAllString(pattern, "*") + // cascade multiple dots and stars + pattern = regexp.MustCompile(`[\.]{2,}\*`).ReplaceAllString(pattern, ".*") + pattern = regexp.MustCompile(`[\*]{2,}`).ReplaceAllString(pattern, "*") + pattern = strings.Replace(pattern, ".(*)?*", ".*", -1) + // when there are wildcards in the middle of the pattern, make them .* + // see https://github.com/konveyor/analyzer-lsp/issues/481 + pattern = regexp.MustCompile(`([A-Za-z])\*([A-Za-z])`).ReplaceAllString(pattern, `$1.*$2`) + return pattern +} + func convertWhereToCustomVars(whereMap map[string]string, fullPattern string) []map[string]interface{} { l := []map[string]interface{}{} newString := fullPattern - // escape any empty paranthesis to avoid interpreting them as wildcards + // escape any empty parenthesis to avoid interpreting them as wildcards newString = strings.Replace(newString, `[]`, `\[\]`, -1) newString = strings.Replace(newString, `()`, `\(\)`, -1) // cascade multiple dots and stars @@ -886,7 +894,7 @@ func convertWindupPerformToAnalyzer(perform windup.Iteration, where map[string]s func substituteWhere(where map[string]string, pattern string) string { newString := pattern for k, v := range where { - newString = strings.ReplaceAll(newString, "{"+k+"}", v) + newString = strings.ReplaceAll(newString, "{"+k+"}", "("+v+")") } return newString } diff --git a/pkg/conversion/convert_test.go b/pkg/conversion/convert_test.go index f3901954..c1edd401 100644 --- a/pkg/conversion/convert_test.go +++ b/pkg/conversion/convert_test.go @@ -138,3 +138,28 @@ func Test_trimMessage(t *testing.T) { }) } } + +func Test_convertJavaPattern(t *testing.T) { + tests := []struct { + name string + where map[string]string + references string + want string + }{ + { + name: "Java pattern substitution should be enclosed by parenthesis", + where: map[string]string{ + "scope": "Application|Request|Session", + }, + references: "javax.faces.bean.{scope}Scoped", + want: "javax.faces.bean.(Application|Request|Session)Scoped", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := convertJavaPattern(tt.where, tt.references); got != tt.want { + t.Errorf("convertJavaPattern() = %v, want %v", got, tt.want) + } + }) + } +} From ba7491c5291acbd7c9c9e8af026b963e4df97fd7 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Mon, 25 Mar 2024 15:54:13 +0100 Subject: [PATCH 2/3] Depend on konveyor-ecosystem repo Signed-off-by: Juan Manuel Leflet Estrada --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9d1ad04a..3f2ba24b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN wget -qO /tmp/windup.zip $WINDUP \ && rm /tmp/windup.zip \ && ln -s /windup/tackle-cli-*/bin/windup-cli /usr/bin/windup-cli -RUN git clone https://github.com/jmle/windup-rulesets.git -b konveyor-tmp /windup-rulesets \ +RUN git clone https://github.com/konveyor-ecosystem/windup-rulesets.git -b eap8-fixes /windup-rulesets \ && git clone https://github.com/konveyor/example-applications /example-applications COPY --from=java-builder /usr/local/openjdk-11 /java-11-openjdk From 02c9df755d7a010845c16cb3e1f227e040ae940a Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Tue, 26 Mar 2024 15:01:27 +0100 Subject: [PATCH 3/3] Depend on latest konveyor branch change Signed-off-by: Juan Manuel Leflet Estrada --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3f2ba24b..d59a53e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN wget -qO /tmp/windup.zip $WINDUP \ && rm /tmp/windup.zip \ && ln -s /windup/tackle-cli-*/bin/windup-cli /usr/bin/windup-cli -RUN git clone https://github.com/konveyor-ecosystem/windup-rulesets.git -b eap8-fixes /windup-rulesets \ +RUN git clone https://github.com/konveyor-ecosystem/windup-rulesets.git -b konveyor /windup-rulesets \ && git clone https://github.com/konveyor/example-applications /example-applications COPY --from=java-builder /usr/local/openjdk-11 /java-11-openjdk