@@ -67,7 +67,7 @@ public class NamingConventionsTask extends LoggedExec {
6767
6868 NamingConventionsTask () {
6969 // Extra classpath contains the actual test
70- if (! project. configurations. names. contains(' namingConventions' )) {
70+ if (false == project. configurations. names. contains(' namingConventions' )) {
7171 project. configurations. create(' namingConventions' )
7272 Dependency buildToolsDep = project. dependencies. add(' namingConventions' ,
7373 " org.elasticsearch.gradle:build-tools:${ VersionProperties.elasticsearch} " )
@@ -81,17 +81,11 @@ public class NamingConventionsTask extends LoggedExec {
8181 description = " Tests that test classes aren't misnamed or misplaced"
8282 executable = new File (project. runtimeJavaHome, ' bin/java' )
8383
84- def dirsToUse = (checkForTestsInMain ?
85- project. sourceSets. main. output. classesDirs :
86- project. sourceSets. test. output. classesDirs)
87- .filter {it. exists()}
88- .collect {it. getAbsolutePath()}
89-
90- if (! checkForTestsInMain) {
84+ if (false == checkForTestsInMain) {
9185 /* This task is created by default for all subprojects with this
9286 * setting and there is no point in running it if the files don't
9387 * exist. */
94- onlyIf { dirsToUse . size () != 0 }
88+ onlyIf { getJavaClassesDir () != null && getJavaClassesDir() . exists() }
9589 }
9690
9791 /*
@@ -124,10 +118,20 @@ public class NamingConventionsTask extends LoggedExec {
124118 } else {
125119 args(' --' )
126120 }
127- args(dirsToUse . join( File . pathSeparator) )
121+ args(getJavaClassesDir() . absolutePath )
128122 }
129123 }
130124 doLast { successMarker. setText(" " , ' UTF-8' ) }
131125 }
132126
127+ File getJavaClassesDir () {
128+ FileCollection classesDirs = (checkForTestsInMain ?
129+ project. sourceSets. main. output. classesDirs :
130+ project. sourceSets. test. output. classesDirs)
131+ if (classesDirs. isEmpty()) { return null }
132+ // see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html the deprecated property
133+ // classesDir is the first in the FileCollection. There seems to be no other way to refer to the Java output dir
134+ // We can't run the check against all classes as Groovy tests don't adhere to naming conventions.
135+ return classesDirs[0 ]
136+ }
133137}
0 commit comments