From c959bda98752b61579825d5557fe207fc7a82841 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 15 May 2024 05:54:57 -0400 Subject: [PATCH 1/6] fix: use match to identify test configuration resolves #390 --- .../gradle/tasks/AbstractAnalyze.groovy | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index 15bb170..d912b5d 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -377,18 +377,15 @@ abstract class AbstractAnalyze extends ConfiguredTask { * Checks whether a configuration is considered to be a test configuration in order to skip it. * A configuration is considered a test configuration if and only if any of the following conditions holds: * + * The intent of the regular expression is to match `test` in a camel case or snake case configuration name. */ @groovy.transform.CompileStatic static boolean isTestConfigurationCheck(Configuration configuration) { - boolean isTestConfiguration = configuration.name.startsWith("test") || configuration.name.startsWith("androidTest") + boolean isTestConfiguration = configuration.name.matches('^(.*[a-z0-9_]T|_?t)est([A-Z0-9_].*)?$') configuration.hierarchy.each { - isTestConfiguration |= (it.name == "testCompile" || it.name == "androidTestCompile" || it.name == "testImplementation") + isTestConfiguration |= it.name.matches('^(.*[a-z0-9_]T|_?t)est([A-Z0-9_].*)?$') } isTestConfiguration } From be04e39d1235d1dba34b043cfb251dc8835ae2a6 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 15 May 2024 17:39:28 -0400 Subject: [PATCH 2/6] style: be more groovy - follow advice from @Vampire and embrace groovy - https://github.com/dependency-check/dependency-check-gradle/issues/390#issuecomment-2112410595 --- .../owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index d912b5d..3a5c990 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -383,9 +383,9 @@ abstract class AbstractAnalyze extends ConfiguredTask { */ @groovy.transform.CompileStatic static boolean isTestConfigurationCheck(Configuration configuration) { - boolean isTestConfiguration = configuration.name.matches('^(.*[a-z0-9_]T|_?t)est([A-Z0-9_].*)?$') + boolean isTestConfiguration = configuration.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ configuration.hierarchy.each { - isTestConfiguration |= it.name.matches('^(.*[a-z0-9_]T|_?t)est([A-Z0-9_].*)?$') + isTestConfiguration |= it.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ } isTestConfiguration } From 28e4022825938e906089ab3dfebba80c1b3c649d Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 15 May 2024 17:45:07 -0400 Subject: [PATCH 3/6] fix: syntax --- .../owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index 3a5c990..a298ceb 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -385,7 +385,7 @@ abstract class AbstractAnalyze extends ConfiguredTask { static boolean isTestConfigurationCheck(Configuration configuration) { boolean isTestConfiguration = configuration.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ configuration.hierarchy.each { - isTestConfiguration |= it.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ + isTestConfiguration |= it.name ==~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ } isTestConfiguration } From 10a6d8f51eb23724133afbfb6ac55e8cdb7ded2d Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 15 May 2024 17:47:23 -0400 Subject: [PATCH 4/6] fix: syntax --- .../owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index a298ceb..f358d2d 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -383,7 +383,7 @@ abstract class AbstractAnalyze extends ConfiguredTask { */ @groovy.transform.CompileStatic static boolean isTestConfigurationCheck(Configuration configuration) { - boolean isTestConfiguration = configuration.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ + boolean isTestConfiguration = configuration.name ==~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ configuration.hierarchy.each { isTestConfiguration |= it.name ==~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ } From bc73a384096ec63d78d1fc9039513113295cd03c Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 15 May 2024 17:55:43 -0400 Subject: [PATCH 5/6] fix: syntax --- .../owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index f358d2d..a298ceb 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -383,7 +383,7 @@ abstract class AbstractAnalyze extends ConfiguredTask { */ @groovy.transform.CompileStatic static boolean isTestConfigurationCheck(Configuration configuration) { - boolean isTestConfiguration = configuration.name ==~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ + boolean isTestConfiguration = configuration.name =~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ configuration.hierarchy.each { isTestConfiguration |= it.name ==~ /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/ } From 533f039d2ec485c3a445fc5cae5d890dd1d8dfca Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Thu, 16 May 2024 05:45:45 -0400 Subject: [PATCH 6/6] docs: update --- .../owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy index a298ceb..ea6fb35 100644 --- a/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy +++ b/src/main/groovy/org/owasp/dependencycheck/gradle/tasks/AbstractAnalyze.groovy @@ -377,7 +377,7 @@ abstract class AbstractAnalyze extends ConfiguredTask { * Checks whether a configuration is considered to be a test configuration in order to skip it. * A configuration is considered a test configuration if and only if any of the following conditions holds: *
    - *
  • the name of the configuration or any of its parent configurations matches /^(.*[a-z0-9_]T|_?t)est([A-Z0-9_].*)?$/
  • + *
  • the name of the configuration or any of its parent configurations matches /((^|[a-z0-9_])T|(^|_)t)est([A-Z0-9_]|$)/
  • *
* The intent of the regular expression is to match `test` in a camel case or snake case configuration name. */