1
1
import org.elasticsearch.gradle.LoggedExec
2
- import org.elasticsearch.gradle.precommit.FeatureAwareTask
2
+ import org.elasticsearch.gradle.plugin.PluginBuildPlugin
3
3
import org.elasticsearch.gradle.test.NodeInfo
4
4
5
5
import java.nio.charset.StandardCharsets
@@ -14,22 +14,46 @@ dependencies {
14
14
}
15
15
16
16
subprojects {
17
- final SourceSet main = project. sourceSets. findByName(" main" )
18
- if (main != null ) {
19
- final FeatureAwareTask featureAwareTask = project. tasks. create(' featureAwareCheck' , FeatureAwareTask . class)
20
-
21
- // see the root Gradle file for additional logic regarding this configuration
22
- project. configurations. create(' featureAwarePlugin' )
23
- project. dependencies. add(
24
- ' featureAwarePlugin' ,
25
- " org.elasticsearch.xpack.test:feature-aware:${ org.elasticsearch.gradle.VersionProperties.elasticsearch} " )
26
- project. dependencies. add(' featureAwarePlugin' , main. output. getClassesDirs())
27
-
28
- featureAwareTask. configure { FeatureAwareTask fat ->
29
- fat. classpath = project. configurations. featureAwarePlugin
30
- }
17
+ afterEvaluate {
18
+ if (project. plugins. hasPlugin(PluginBuildPlugin )) {
19
+ // see the root Gradle file for additional logic regarding this configuration
20
+ project. configurations. create(' featureAwarePlugin' )
21
+ project. dependencies. add(' featureAwarePlugin' , project. configurations. runtime)
22
+ project. dependencies. add(
23
+ ' featureAwarePlugin' ,
24
+ " org.elasticsearch.xpack.test:feature-aware:${ org.elasticsearch.gradle.VersionProperties.elasticsearch} " )
25
+ project. dependencies. add(' featureAwarePlugin' , project. sourceSets. main. output. getClassesDirs())
26
+
27
+ final Task featureAwareTask = project. tasks. create(" featureAwareCheck" , LoggedExec ) {
28
+ description = " Runs FeatureAwareCheck on main classes."
29
+ dependsOn project. configurations. featureAwarePlugin
30
+
31
+ final File successMarker = new File (project. buildDir, ' markers/featureAware' )
32
+ outputs. file(successMarker)
33
+
34
+ executable = new File (project. runtimeJavaHome, ' bin/java' )
35
+
36
+ // default to main class files if such a source set exists
37
+ final List files = []
38
+ if (project. sourceSets. findByName(" main" )) {
39
+ files. add(project. sourceSets. main. output. classesDir)
40
+ dependsOn project. tasks. classes
41
+ }
42
+ // filter out non-existent classes directories from empty source sets
43
+ final FileCollection classDirectories = project. files(files). filter { it. exists() }
31
44
32
- project. precommit. dependsOn featureAwareTask
45
+ doFirst {
46
+ args(' -cp' , project. configurations. featureAwarePlugin. asPath, ' org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck' )
47
+ classDirectories. each { args it. getAbsolutePath() }
48
+ }
49
+ doLast {
50
+ successMarker. parentFile. mkdirs()
51
+ successMarker. setText(" " , ' UTF-8' )
52
+ }
53
+ }
54
+
55
+ project. precommit. dependsOn featureAwareTask
56
+ }
33
57
}
34
58
}
35
59
0 commit comments