Skip to content

Commit

Permalink
Minor polish of TestingConventionsTasks and plugin (#84320) (#84609)
Browse files Browse the repository at this point in the history
We can build a named object container within a task using the objectfactory.
This makes constructing the task way simpler and does not require us to
inject the container from the constructing plugin
  • Loading branch information
breskeby committed Mar 3, 2022
1 parent 3700f76 commit 3e86905
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.gradle.internal.InternalPlugin;
import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.SourceSetContainer;
Expand All @@ -25,14 +24,11 @@ public class TestingConventionsPrecommitPlugin extends PrecommitPlugin implement
public TaskProvider<? extends Task> createTask(Project project) {
TaskProvider<TestingConventionsTasks> testingConventions = project.getTasks()
.register("testingConventions", TestingConventionsTasks.class, t -> {
NamedDomainObjectContainer<TestingConventionRule> namings = project.container(TestingConventionRule.class);
TestingConventionRule testsRule = namings.maybeCreate("Tests");
TestingConventionRule testsRule = t.getNaming().maybeCreate("Tests");
testsRule.baseClass("org.apache.lucene.util.LuceneTestCase");
TestingConventionRule itRule = namings.maybeCreate("IT");
TestingConventionRule itRule = t.getNaming().maybeCreate("IT");
itRule.baseClass("org.elasticsearch.test.ESIntegTestCase");
itRule.baseClass("org.elasticsearch.test.rest.ESRestTestCase");

t.setNaming(namings);
t.setCandidateClassFilesProvider(
project.provider(
() -> project.getTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -65,8 +66,9 @@ public void setCandidateClassFilesProvider(Provider<Map<String, Set<File>>> cand
}

@Inject
public TestingConventionsTasks(ProjectLayout projectLayout) {
public TestingConventionsTasks(ProjectLayout projectLayout, ObjectFactory objectFactory) {
this.projectLayout = projectLayout;
this.naming = objectFactory.domainObjectContainer(TestingConventionRule.class);
setDescription("Tests various testing conventions");
}

Expand Down Expand Up @@ -417,8 +419,4 @@ private URL fileToUrl(File file) {
public void setSourceSets(SourceSetContainer sourceSets) {
this.sourceSets = sourceSets;
}

public void setNaming(NamedDomainObjectContainer<TestingConventionRule> naming) {
this.naming = naming;
}
}

0 comments on commit 3e86905

Please sign in to comment.