@@ -36,16 +36,18 @@ class InstrumentationNamingPlugin : Plugin<Project> {
3636 doLast {
3737 val instrumentationsDir = target.rootProject.file(extension.instrumentationsDir.get())
3838 val exclusions = extension.exclusions.get().toSet()
39+ val suffixes = extension.suffixes.get()
3940
4041 if (! instrumentationsDir.exists() || ! instrumentationsDir.isDirectory) {
4142 throw GradleException (
4243 " Instrumentations directory not found: ${instrumentationsDir.absolutePath} "
4344 )
4445 }
4546
46- val violations = validateInstrumentations(instrumentationsDir, exclusions)
47+ val violations = validateInstrumentations(instrumentationsDir, exclusions, suffixes )
4748
4849 if (violations.isNotEmpty()) {
50+ val suffixesStr = suffixes.joinToString(" ', '" , " '" , " '" )
4951 val errorMessage = buildString {
5052 appendLine(" \n Instrumentation naming convention violations found:" )
5153 appendLine()
@@ -55,13 +57,14 @@ class InstrumentationNamingPlugin : Plugin<Project> {
5557 appendLine()
5658 }
5759 appendLine(" Naming rules:" )
58- appendLine(" 1. Module name must end with a version (e.g., '2.0', '3.1') OR end with '-common' " )
60+ appendLine(" 1. Module name must end with a version (e.g., '2.0', '3.1') OR one of: $suffixesStr " )
5961 appendLine(" 2. Module name must include the parent directory name" )
6062 appendLine(" Example: 'couchbase/couchbase-2.0' ✓ (contains 'couchbase')" )
6163 appendLine()
62- appendLine(" To exclude specific modules, configure the plugin:" )
64+ appendLine(" To exclude specific modules or customize suffixes , configure the plugin:" )
6365 appendLine(" instrumentationNaming {" )
6466 appendLine(" exclusions.set(listOf(\" module-name\" ))" )
67+ appendLine(" suffixes.set(listOf(\" -common\" , \" -stubs\" ))" )
6568 appendLine(" }" )
6669 }
6770 throw GradleException (errorMessage)
@@ -74,7 +77,8 @@ class InstrumentationNamingPlugin : Plugin<Project> {
7477
7578 private fun validateInstrumentations (
7679 instrumentationsDir : File ,
77- exclusions : Set <String >
80+ exclusions : Set <String >,
81+ suffixes : List <String >
7882 ): List <NamingViolation > {
7983 val violations = mutableListOf<NamingViolation >()
8084
@@ -96,7 +100,7 @@ class InstrumentationNamingPlugin : Plugin<Project> {
96100 if (hasBuildFile) {
97101 // This is a leaf module, validate only the version/common suffix requirement
98102 if (parentName !in exclusions) {
99- validateLeafModuleName(parentName, parentDir.relativeTo(instrumentationsDir).path)?.let {
103+ validateLeafModuleName(parentName, parentDir.relativeTo(instrumentationsDir).path, suffixes )?.let {
100104 violations.add(it)
101105 }
102106 }
@@ -116,7 +120,7 @@ class InstrumentationNamingPlugin : Plugin<Project> {
116120 } ? : false
117121
118122 if (hasModuleBuildFile && moduleName !in exclusions) {
119- validateModuleName(moduleName, parentName, moduleDir.relativeTo(instrumentationsDir).path)?.let {
123+ validateModuleName(moduleName, parentName, moduleDir.relativeTo(instrumentationsDir).path, suffixes )?.let {
120124 violations.add(it)
121125 }
122126 }
@@ -130,21 +134,13 @@ class InstrumentationNamingPlugin : Plugin<Project> {
130134 private fun validateModuleName (
131135 moduleName : String ,
132136 parentName : String ,
133- relativePath : String
137+ relativePath : String ,
138+ suffixes : List <String >
134139 ): NamingViolation ? {
135- // Rule 1: Module name must end with version pattern (X.Y, X.Y.Z, etc.) or "-common"
136- val endsWithCommon = moduleName.endsWith(" -common" )
137- val endsWithVersion = versionPattern.containsMatchIn(moduleName)
138-
139- if (! endsWithVersion && ! endsWithCommon) {
140- return NamingViolation (
141- relativePath,
142- " Module name '$moduleName ' must end with a version (e.g., '2.0', '3.1.0') or '-common'"
143- )
144- }
140+ // Rule 1: Module name must end with version pattern or one of the configured suffixes
141+ validateVersionOrSuffix(moduleName, relativePath, suffixes)?.let { return it }
145142
146143 // Rule 2: Module name must contain parent directory name
147- // Extract the base name (without version or -common suffix)
148144 if (! moduleName.contains(parentName, ignoreCase = true )) {
149145 return NamingViolation (
150146 relativePath,
@@ -157,20 +153,32 @@ class InstrumentationNamingPlugin : Plugin<Project> {
157153
158154 /* *
159155 * Validates naming for leaf modules (modules at the top level with no parent grouping).
160- * These only need to check the version/common suffix requirement.
156+ * These only need to check the version/suffix requirement.
161157 */
162158 private fun validateLeafModuleName (
163159 moduleName : String ,
164- relativePath : String
160+ relativePath : String ,
161+ suffixes : List <String >
162+ ): NamingViolation ? {
163+ return validateVersionOrSuffix(moduleName, relativePath, suffixes)
164+ }
165+
166+ /* *
167+ * Validates that a module name ends with either a version or one of the configured suffixes.
168+ */
169+ private fun validateVersionOrSuffix (
170+ moduleName : String ,
171+ relativePath : String ,
172+ suffixes : List <String >
165173 ): NamingViolation ? {
166- // Rule: Module name must end with version pattern (X.Y, X.Y.Z, etc.) or "-common"
167- val endsWithCommon = moduleName.endsWith(" -common" )
174+ val endsWithSuffix = suffixes.any { moduleName.endsWith(it) }
168175 val endsWithVersion = versionPattern.containsMatchIn(moduleName)
169176
170- if (! endsWithVersion && ! endsWithCommon) {
177+ if (! endsWithVersion && ! endsWithSuffix) {
178+ val suffixesStr = suffixes.joinToString(" ', '" , " '" , " '" )
171179 return NamingViolation (
172180 relativePath,
173- " Module name '$moduleName ' must end with a version (e.g., '2.0', '3.1.0') or '-common' "
181+ " Module name '$moduleName ' must end with a version (e.g., '2.0', '3.1.0') or one of: $suffixesStr "
174182 )
175183 }
176184
0 commit comments