Skip to content

Commit 6344e9a

Browse files
authored
Testing conventions: add support for checking base classes (#36650)
1 parent 0c68eea commit 6344e9a

File tree

61 files changed

+1192
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1192
-78
lines changed

buildSrc/build.gradle

+12
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ if (project != rootProject) {
223223
integTestClass = 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
224224
}
225225

226+
testingConventions {
227+
naming.clear()
228+
naming {
229+
Tests {
230+
baseClass 'org.elasticsearch.gradle.test.GradleUnitTestCase'
231+
}
232+
IT {
233+
baseClass 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
234+
}
235+
}
236+
}
237+
226238
/*
227239
* We alread configure publication and we don't need or want this one that
228240
* comes from the java-gradle-plugin.

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ public class PluginBuildPlugin extends BuildPlugin {
7878
skipIntegTestInDisguise = true
7979
}
8080
}
81+
project.testingConventions {
82+
naming.clear()
83+
naming {
84+
Tests {
85+
baseClass 'org.apache.lucene.util.LuceneTestCase'
86+
}
87+
IT {
88+
baseClass 'org.elasticsearch.test.ESIntegTestCase'
89+
baseClass 'org.elasticsearch.test.rest.ESRestTestCase'
90+
baseClass 'org.elasticsearch.test.ESSingleNodeTestCase'
91+
}
92+
}
93+
}
8194
createIntegTestTask(project)
8295
createBundleTask(project)
8396
project.configurations.getByName('default').extendsFrom(project.configurations.getByName('runtime'))

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

+11-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ class PrecommitTasks {
9191
}
9292

9393
static Task configureTestingConventions(Project project) {
94-
project.getTasks().create("testingConventions", TestingConventionsTasks.class)
94+
TestingConventionsTasks task = project.getTasks().create("testingConventions", TestingConventionsTasks.class)
95+
task.naming {
96+
Tests {
97+
baseClass "org.apache.lucene.util.LuceneTestCase"
98+
}
99+
IT {
100+
baseClass "org.elasticsearch.test.ESIntegTestCase"
101+
baseClass 'org.elasticsearch.test.rest.ESRestTestCase'
102+
}
103+
}
104+
return task
95105
}
96106

97107
private static Task configureJarHell(Project project) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.gradle.precommit;
20+
21+
import java.io.Serializable;
22+
import java.util.Collection;
23+
import java.util.HashSet;
24+
import java.util.Objects;
25+
import java.util.Set;
26+
import java.util.regex.Pattern;
27+
28+
/**
29+
* Represent rules for tests enforced by the @{link {@link TestingConventionsTasks}}
30+
*
31+
* Rules are identified by name, tests must have this name as a suffix and implement one of the base classes
32+
* and be part of all the specified tasks.
33+
*/
34+
public class TestingConventionRule implements Serializable {
35+
36+
private final String suffix;
37+
38+
private Set<String> baseClasses = new HashSet<>();
39+
40+
private Set<Pattern> taskNames = new HashSet<>();
41+
42+
public TestingConventionRule(String suffix) {
43+
this.suffix = suffix;
44+
}
45+
46+
public String getSuffix() {
47+
return suffix;
48+
}
49+
50+
/**
51+
* Alias for @{link getSuffix} as Gradle requires a name property
52+
*
53+
*/
54+
public String getName() {
55+
return suffix;
56+
}
57+
58+
public void baseClass(String clazz) {
59+
baseClasses.add(clazz);
60+
}
61+
62+
public void setBaseClasses(Collection<String> baseClasses) {
63+
this.baseClasses.clear();
64+
this.baseClasses.addAll(baseClasses);
65+
}
66+
67+
public void taskName(Pattern expression) {
68+
taskNames.add(expression);
69+
}
70+
public void taskName(String expression) {
71+
taskNames.add(Pattern.compile(expression));
72+
}
73+
74+
public void setTaskNames(Collection<Pattern> expressions) {
75+
taskNames.clear();
76+
taskNames.addAll(expressions);
77+
}
78+
79+
public Set<String> getBaseClasses() {
80+
return baseClasses;
81+
}
82+
83+
public Set<Pattern> getTaskNames() {
84+
return taskNames;
85+
}
86+
87+
@Override
88+
public boolean equals(Object o) {
89+
if (this == o) return true;
90+
if (o == null || getClass() != o.getClass()) return false;
91+
TestingConventionRule that = (TestingConventionRule) o;
92+
return Objects.equals(suffix, that.suffix);
93+
}
94+
95+
@Override
96+
public int hashCode() {
97+
return Objects.hash(suffix);
98+
}
99+
}

0 commit comments

Comments
 (0)