Fix Gradle Plugin

Fix IncludeCheckRemotePlugin to add the default tasks even without defining the extension properties

Issue gh-9846
This commit is contained in:
Marcus Da Coregio 2021-07-30 11:29:53 -03:00
parent d5c953b106
commit 87687bf03f
2 changed files with 18 additions and 7 deletions

View File

@ -33,8 +33,8 @@ class IncludeCheckRemotePlugin implements Plugin<Project> {
void apply(Project project) {
IncludeCheckRemoteExtension extension = project.extensions.create('includeCheckRemote', IncludeCheckRemoteExtension)
TaskProvider<IncludeRepoTask> includeRepoTask = project.tasks.register('includeRepo', IncludeRepoTask) { IncludeRepoTask it ->
it.repository = extension.repository.get()
it.ref = extension.ref.get()
it.repository = extension.repository
it.ref = extension.ref
}
project.tasks.register('checkRemote', GradleBuild) {
it.dependsOn 'includeRepo'
@ -44,22 +44,22 @@ class IncludeCheckRemotePlugin implements Plugin<Project> {
}
abstract static class IncludeCheckRemoteExtension {
/**
* Git repository to clone
*/
abstract Property<String> getRepository();
String repository;
/**
* Git ref to checkout
*/
abstract Property<String> getRef();
String ref
/**
* Task to run in the repository
*/
List<String> tasks = ['check']
void setTask(List<String> tasks) {
this.tasks = tasks
}
}
}

View File

@ -97,4 +97,15 @@ class IncludeCheckRemotePluginTest {
GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get();
assertThat(checkRemote.getDir()).isEqualTo(includeRepo.getOutputDirectory());
}
@Test
void applyWhenNoExtensionPropertiesThenRegisterTasks() {
this.rootProject = ProjectBuilder.builder().build();
this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class);
IncludeRepoTask includeRepo = (IncludeRepoTask) this.rootProject.getTasks().named("includeRepo").get();
GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get();
assertThat(includeRepo).isNotNull();
assertThat(checkRemote).isNotNull();
}
}