|
18 | 18 | */
|
19 | 19 | package org.elasticsearch.gradle.precommit
|
20 | 20 |
|
| 21 | +import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis |
21 | 22 | import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
|
22 | 23 | import org.gradle.api.Project
|
23 | 24 | import org.gradle.api.Task
|
@@ -83,17 +84,14 @@ class PrecommitTasks {
|
83 | 84 | getClass().getResource('/forbidden/es-all-signatures.txt')]
|
84 | 85 | suppressAnnotations = ['**.SuppressForbidden']
|
85 | 86 | }
|
86 |
| - Task mainForbidden = project.tasks.findByName('forbiddenApisMain') |
87 |
| - if (mainForbidden != null) { |
88 |
| - mainForbidden.configure { |
89 |
| - signaturesURLs += getClass().getResource('/forbidden/es-server-signatures.txt') |
90 |
| - } |
91 |
| - } |
92 |
| - Task testForbidden = project.tasks.findByName('forbiddenApisTest') |
93 |
| - if (testForbidden != null) { |
94 |
| - testForbidden.configure { |
95 |
| - signaturesURLs += getClass().getResource('/forbidden/es-test-signatures.txt') |
96 |
| - signaturesURLs += getClass().getResource('/forbidden/http-signatures.txt') |
| 87 | + project.tasks.withType(CheckForbiddenApis) { |
| 88 | + // we do not use the += operator to add signatures, as conventionMappings of Gradle do not work when it's configured using withType: |
| 89 | + if (name.endsWith('Test')) { |
| 90 | + signaturesURLs = project.forbiddenApis.signaturesURLs + |
| 91 | + [ getClass().getResource('/forbidden/es-test-signatures.txt'), getClass().getResource('/forbidden/http-signatures.txt') ] |
| 92 | + } else { |
| 93 | + signaturesURLs = project.forbiddenApis.signaturesURLs + |
| 94 | + [ getClass().getResource('/forbidden/es-server-signatures.txt') ] |
97 | 95 | }
|
98 | 96 | }
|
99 | 97 | Task forbiddenApis = project.tasks.findByName('forbiddenApis')
|
@@ -144,21 +142,15 @@ class PrecommitTasks {
|
144 | 142 | ]
|
145 | 143 | toolVersion = 7.5
|
146 | 144 | }
|
147 |
| - for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) { |
148 |
| - Task task = project.tasks.findByName(taskName) |
149 |
| - if (task != null) { |
150 |
| - project.tasks['check'].dependsOn.remove(task) |
151 |
| - checkstyleTask.dependsOn(task) |
152 |
| - task.dependsOn(copyCheckstyleConf) |
153 |
| - task.inputs.file(checkstyleSuppressions) |
154 |
| - task.reports { |
155 |
| - html.enabled false |
156 |
| - } |
157 |
| - } |
158 |
| - } |
159 | 145 |
|
160 |
| - project.tasks.withType(Checkstyle) { |
161 |
| - dependsOn(copyCheckstyleConf) |
| 146 | + project.tasks.withType(Checkstyle) { task -> |
| 147 | + project.tasks[JavaBasePlugin.CHECK_TASK_NAME].dependsOn.remove(task) |
| 148 | + checkstyleTask.dependsOn(task) |
| 149 | + task.dependsOn(copyCheckstyleConf) |
| 150 | + task.inputs.file(checkstyleSuppressions) |
| 151 | + task.reports { |
| 152 | + html.enabled false |
| 153 | + } |
162 | 154 | }
|
163 | 155 |
|
164 | 156 | return checkstyleTask
|
|
0 commit comments