Skip to content

Commit 79b81f8

Browse files
Merge branch 'master' into snapshot_only_role
2 parents e045d2f + 864e465 commit 79b81f8

File tree

212 files changed

+3420
-6207
lines changed

Some content is hidden

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

212 files changed

+3420
-6207
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ task verifyVersions {
159159
* the enabled state of every bwc task. It should be set back to true
160160
* after the backport of the backcompat code is complete.
161161
*/
162-
final boolean bwc_tests_enabled = true
163-
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
162+
final boolean bwc_tests_enabled = false
163+
final String bwc_tests_disabled_issue = "backporting https://github.com/elastic/elasticsearch/pull/37639" /* place a PR link here when committing bwc changes */
164164
if (bwc_tests_enabled == false) {
165165
if (bwc_tests_disabled_issue.isEmpty()) {
166166
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

buildSrc/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,6 @@ if (project != rootProject) {
235235
exclude '**/ForbiddenPatternsTask.java'
236236
}
237237

238-
namingConventions {
239-
testClass = 'org.elasticsearch.gradle.test.GradleUnitTestCase'
240-
integTestClass = 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
241-
}
242-
243238
testingConventions {
244239
naming.clear()
245240
naming {

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ class BuildPlugin implements Plugin<Project> {
904904
project.tasks.withType(RandomizedTestingTask) {task ->
905905
jvm "${project.runtimeJavaHome}/bin/java"
906906
parallelism System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
907+
ifNoTests 'fail'
907908
onNonEmptyWorkDirectory 'wipe'
908909
leaveTemporary true
909910
project.sourceSets.matching { it.name == "test" }.all { test ->

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ public class PluginBuildPlugin extends BuildPlugin {
7272
if (isModule == false || isXPackModule) {
7373
addNoticeGeneration(project)
7474
}
75-
76-
project.namingConventions {
77-
// Plugins declare integration tests as "Tests" instead of IT.
78-
skipIntegTestInDisguise = true
79-
}
8075
}
8176
project.testingConventions {
8277
naming.clear()

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class PrecommitTasks {
4343
List<Task> precommitTasks = [
4444
configureCheckstyle(project),
4545
configureForbiddenApisCli(project),
46-
configureNamingConventions(project),
4746
project.tasks.create('forbiddenPatterns', ForbiddenPatternsTask.class),
4847
project.tasks.create('licenseHeaders', LicenseHeadersTask.class),
4948
project.tasks.create('filepermissions', FilePermissionsTask.class),
@@ -230,15 +229,6 @@ class PrecommitTasks {
230229
return checkstyleTask
231230
}
232231

233-
private static Task configureNamingConventions(Project project) {
234-
if (project.sourceSets.findByName("test")) {
235-
Task namingConventionsTask = project.tasks.create('namingConventions', NamingConventionsTask)
236-
namingConventionsTask.javaHome = project.compilerJavaHome
237-
return namingConventionsTask
238-
}
239-
return null
240-
}
241-
242232
private static Task configureLoggerUsage(Project project) {
243233
project.configurations.create('loggerUsagePlugin')
244234
project.dependencies.add('loggerUsagePlugin',

buildSrc/src/main/java/org/elasticsearch/gradle/precommit/NamingConventionsTask.java

Lines changed: 0 additions & 167 deletions
This file was deleted.

buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.gradle.api.file.FileTree;
2828
import org.gradle.api.tasks.Input;
2929
import org.gradle.api.tasks.OutputFile;
30+
import org.gradle.api.tasks.SourceSet;
31+
import org.gradle.api.tasks.SourceSetContainer;
3032
import org.gradle.api.tasks.TaskAction;
3133
import org.gradle.api.tasks.testing.Test;
3234
import org.gradle.api.tasks.util.PatternFilterable;
@@ -122,6 +124,23 @@ public void naming(Closure<TestingConventionRule> action) {
122124
naming.configure(action);
123125
}
124126

127+
@Input
128+
public Set<String> getMainClassNamedLikeTests() {
129+
SourceSetContainer javaSourceSets = Boilerplate.getJavaSourceSets(getProject());
130+
if (javaSourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME) == null) {
131+
// some test projects don't have a main source set
132+
return Collections.emptySet();
133+
}
134+
return javaSourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
135+
.getOutput().getClassesDirs().getAsFileTree()
136+
.getFiles().stream()
137+
.filter(file -> file.getName().endsWith(".class"))
138+
.map(File::getName)
139+
.map(name -> name.substring(0, name.length() - 6))
140+
.filter(this::implementsNamingConvention)
141+
.collect(Collectors.toSet());
142+
}
143+
125144
@TaskAction
126145
public void doCheck() throws IOException {
127146
final String problems;
@@ -235,10 +254,12 @@ public void doCheck() throws IOException {
235254
);
236255
}).sorted()
237256
.collect(Collectors.joining("\n"))
238-
)
257+
),
239258
// TODO: check that the testing tasks are included in the right task based on the name ( from the rule )
240-
// TODO: check to make sure that the main source set doesn't have classes that match
241-
// the naming convention (just the names, don't load classes)
259+
checkNoneExists(
260+
"Classes matching the test naming convention should be in test not main",
261+
getMainClassNamedLikeTests()
262+
)
242263
);
243264
}
244265

@@ -296,6 +317,18 @@ private String checkNoneExists(String message, Stream<? extends Class<?>> stream
296317
}
297318
}
298319

320+
private String checkNoneExists(String message, Set<? extends String> candidates) {
321+
String problem = candidates.stream()
322+
.map(each -> " * " + each)
323+
.sorted()
324+
.collect(Collectors.joining("\n"));
325+
if (problem.isEmpty() == false) {
326+
return message + ":\n" + problem;
327+
} else {
328+
return "";
329+
}
330+
}
331+
299332
private String checkAtLeastOneExists(String message, Stream<? extends Class<?>> stream) {
300333
if (stream.findAny().isPresent()) {
301334
return "";
@@ -337,10 +370,14 @@ private boolean seemsLikeATest(Class<?> clazz) {
337370
}
338371

339372
private boolean implementsNamingConvention(Class<?> clazz) {
373+
return implementsNamingConvention(clazz.getName());
374+
}
375+
376+
private boolean implementsNamingConvention(String className) {
340377
if (naming.stream()
341378
.map(TestingConventionRule::getSuffix)
342-
.anyMatch(suffix -> clazz.getName().endsWith(suffix))) {
343-
getLogger().debug("{} is a test because it matches the naming convention", clazz.getName());
379+
.anyMatch(suffix -> className.endsWith(suffix))) {
380+
getLogger().debug("{} is a test because it matches the naming convention", className);
344381
return true;
345382
}
346383
return false;

0 commit comments

Comments
 (0)