11import java.nio.file.Files
2+ import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
3+ import org.gradle.api.tasks.Input ;
4+ import org.gradle.process.CommandLineArgumentProvider ;
5+
6+ import java.util.LinkedHashMap ;
7+ import java.util.Map ;
8+ import java.util.function.Supplier ;
9+ import java.util.stream.Collectors ;
210
311buildscript {
412 dependencies {
@@ -22,31 +30,22 @@ version = "${elasticsearchVersion}.1-SNAPSHOT"
2230apply plugin : ' java'
2331apply plugin : ' idea'
2432apply plugin : ' elasticsearch.esplugin'
25- apply plugin : ' elasticsearch.yaml-rest-test'
26-
27- // license of this project
28- licenseFile = rootProject. file(' LICENSE.txt' )
29- // copyright notices
30- noticeFile = rootProject. file(' NOTICE.txt' )
33+ apply plugin : ' elasticsearch.testclusters'
3134
3235esplugin {
33- name ' ingest-langdetect'
34- description ' Ingest processor doing language detection for fields'
35- classname ' org.elasticsearch.plugin.ingest.langdetect.IngestLangDetectPlugin'
36- // license of the plugin, may be different than the above license
37- licenseFile rootProject. file(' LICENSE.txt' )
38- // copyright notices, may be different than the above notice
39- noticeFile rootProject. file(' NOTICE.txt' )
36+ name = ' ingest-langdetect'
37+ description = ' Ingest processor doing language detection for fields'
38+ classname = ' org.elasticsearch.plugin.ingest.langdetect.IngestLangDetectPlugin'
39+ licenseFile = rootProject. file(' LICENSE.txt' )
40+ noticeFile = rootProject. file(' NOTICE.txt' )
4041}
4142
42- validateElasticPom. enabled = false
43-
4443// In this section you declare the dependencies for your production and test code
4544dependencies {
4645 implementation ' com.youcruit.com.cybozu.labs:langdetect:1.1.2-20151117'
4746 implementation ' net.arnx:jsonic:1.3.10'
4847 // the yaml tests require a log4j2 dependency, otherwise a dependency is thrown on startup
49- yamlRestTestImplementation ' org.apache.logging.log4j:log4j-core:2.11.1'
48+ runtimeOnly ' org.apache.logging.log4j:log4j-core:2.11.1'
5049}
5150
5251// ignore javadoc warnings for now
@@ -76,3 +75,97 @@ githubRelease.doFirst {
7675 assets = [ filename ]
7776 }
7877}
78+
79+
80+ // setup yaml rest tests
81+ testClusters {
82+ yamlRestTest
83+ }
84+
85+ sourceSets {
86+ yamlRestTest
87+ }
88+
89+ configurations {
90+ yamlRestTestImplementation. extendsFrom testImplementation
91+ yamlRestTestRuntimeOnly. extendsFrom testRuntimeOnly
92+ restTestSpecs
93+ }
94+
95+ tasks. register(' copyRestTestSpecs' , Copy ) {
96+ from zipTree(configurations. restTestSpecs. singleFile)
97+ into " $buildDir /restResources/restspec"
98+ }
99+
100+ TaskProvider<Zip > bundle = project. getTasks(). withType(Zip . class). named(" bundlePlugin" );
101+
102+ // Register rest resources with source set
103+ sourceSets. yamlRestTest. getOutput(). dir(" $buildDir /restResources/restspec" );
104+
105+ tasks. register(' yamlRestTest' , StandaloneRestIntegTestTask ) { testTask ->
106+ testTask. dependsOn(bundle, ' copyRestTestSpecs' )
107+
108+ def cluster = testClusters. yamlRestTest
109+ cluster. plugin(bundle. flatMap(AbstractArchiveTask ::getArchiveFile))
110+ testTask. useCluster(testClusters. yamlRestTest)
111+
112+ testTask. mustRunAfter(project. getTasks(). named(" test" ))
113+ testTask. setTestClassesDirs(sourceSets. yamlRestTest. getOutput(). getClassesDirs())
114+ testTask. setClasspath(sourceSets. yamlRestTest. getRuntimeClasspath())
115+
116+
117+ SystemPropertyCommandLineArgumentProvider nonInputProperties = new SystemPropertyCommandLineArgumentProvider ()
118+ nonInputProperties. systemProperty(" tests.rest.cluster" , " ${ -> String.join(",", cluster.getAllHttpSocketURI())} " )
119+ nonInputProperties. systemProperty(" tests.cluster" , " ${ -> String.join(",", cluster.getAllTransportPortURI())} " )
120+ nonInputProperties. systemProperty(" tests.clustername" , " ${ -> cluster.getName()} " )
121+ testTask. getJvmArgumentProviders(). add(nonInputProperties)
122+ testTask. systemProperty(" tests.rest.load_packaged" , Boolean . FALSE . toString())
123+ }
124+
125+ // this is a bit of a hack to make sure we run the test tests when releasing...
126+ check. dependsOn ' yamlRestTest'
127+
128+ dependencies {
129+ yamlRestTestImplementation " org.elasticsearch.test:framework:$elasticsearchVersion "
130+ restTestSpecs " org.elasticsearch:rest-api-spec:$elasticsearchVersion "
131+ }
132+
133+ // remove when 7.14.1 is released
134+ tasks. withType(Test ). configureEach { testTask ->
135+ testTask. systemProperties ' gradle.dist.lib' : " ${ gradle.gradleHomeDir} /lib" ,
136+ ' gradle.worker.jar' : " ${ gradle.gradleUserHomeDir} /caches/${ gradle.gradleVersion} /workerMain/gradle-worker.jar" ,
137+ ' tests.gradle' : ' true' ,
138+ ' tests.task' : testTask. path
139+ }
140+
141+ // This will be available in 7.15 in build tools and not manually declared.
142+ public class SystemPropertyCommandLineArgumentProvider implements CommandLineArgumentProvider {
143+ private final Map<String , Object > systemProperties = new LinkedHashMap<> ();
144+
145+ public void systemProperty (String key , Supplier<String > value ) {
146+ systemProperties. put(key, value);
147+ }
148+
149+ public void systemProperty (String key , Object value ) {
150+ systemProperties. put(key, value);
151+ }
152+
153+ @Override
154+ public Iterable<String > asArguments () {
155+ return systemProperties. entrySet()
156+ .stream()
157+ .map(
158+ entry -> " -D"
159+ + entry. getKey()
160+ + " ="
161+ + (entry. getValue() instanceof Supplier ? ((Supplier ) entry. getValue()). get() : entry. getValue())
162+ )
163+ .collect(Collectors . toList());
164+ }
165+
166+ // Track system property keys as an input so our build cache key will change if we add properties but values are still ignored
167+ @Input
168+ public Iterable<String > getPropertyNames () {
169+ return systemProperties. keySet();
170+ }
171+ }
0 commit comments