3434import org .gradle .api .file .RegularFileProperty ;
3535import org .gradle .api .internal .DocumentationRegistry ;
3636import org .gradle .api .model .ObjectFactory ;
37+ import org .gradle .api .provider .Property ;
3738import org .gradle .api .tasks .CacheableTask ;
3839import org .gradle .api .tasks .Classpath ;
3940import org .gradle .api .tasks .Input ;
4546import org .gradle .api .tasks .SkipWhenEmpty ;
4647import org .gradle .api .tasks .TaskAction ;
4748import org .gradle .api .tasks .TaskValidationException ;
48- import org .gradle .api .tasks .VerificationTask ;
4949import org .gradle .internal .classanalysis .AsmConstants ;
5050import org .gradle .internal .classloader .ClassLoaderFactory ;
5151import org .gradle .internal .classloader .ClassLoaderUtils ;
7676 */
7777@ CacheableTask
7878@ Incubating
79- public class ValidatePlugins extends DefaultTask implements VerificationTask {
79+ public class ValidatePlugins extends DefaultTask {
8080 private final ConfigurableFileCollection classes ;
8181 private final ConfigurableFileCollection classpath ;
8282 private final RegularFileProperty outputFile ;
83- private boolean enableStricterValidation ;
84- private boolean ignoreFailures ;
85- private boolean failOnWarning = true ;
83+ private final Property < Boolean > enableStricterValidation ;
84+ private final Property < Boolean > ignoreFailures ;
85+ private final Property < Boolean > failOnWarning ;
8686
8787 @ Inject
8888 public ValidatePlugins (ObjectFactory objects ) {
8989 this .classes = objects .fileCollection ();
9090 this .classpath = objects .fileCollection ();
9191 this .outputFile = objects .fileProperty ();
92+ this .enableStricterValidation = objects .property (Boolean .class ).convention (false );
93+ this .ignoreFailures = objects .property (Boolean .class ).convention (false );
94+ this .failOnWarning = objects .property (Boolean .class ).convention (true );
9295 }
9396
9497 @ TaskAction
@@ -137,7 +140,7 @@ public void visitFile(FileVisitDetails fileDetails) {
137140 throw new GradleException ("Could not load class: " + className , e );
138141 }
139142 try {
140- validatorMethod .invoke (null , clazz , taskValidationProblems , enableStricterValidation );
143+ validatorMethod .invoke (null , clazz , taskValidationProblems , enableStricterValidation . get () );
141144 } catch (IllegalAccessException | InvocationTargetException e ) {
142145 throw new RuntimeException (e );
143146 }
@@ -162,8 +165,8 @@ private void communicateResult(List<String> problemMessages, boolean hasErrors)
162165 if (problemMessages .isEmpty ()) {
163166 getLogger ().info ("Plugin validation finished without warnings." );
164167 } else {
165- if (hasErrors || getFailOnWarning ()) {
166- if (getIgnoreFailures ()) {
168+ if (hasErrors || failOnWarning . get ()) {
169+ if (ignoreFailures . get ()) {
167170 getLogger ().warn ("Plugin validation finished with errors. See {} for more information on how to annotate task properties.{}" , getDocumentationRegistry ().getDocumentationFor ("more_about_tasks" , "sec:task_input_output_annotations" ), toMessageList (problemMessages ));
168171 } else {
169172 throw new TaskValidationException (String .format ("Plugin validation failed. See %s for more information on how to annotate task properties." , getDocumentationRegistry ().getDocumentationFor ("more_about_tasks" , "sec:task_input_output_annotations" )), toExceptionList (problemMessages ));
@@ -201,22 +204,6 @@ private static List<InvalidUserDataException> toExceptionList(List<String> probl
201204 .collect (Collectors .toList ());
202205 }
203206
204- /**
205- * {@inheritDoc}
206- */
207- @ Override
208- public boolean getIgnoreFailures () {
209- return ignoreFailures ;
210- }
211-
212- /**
213- * {@inheritDoc}
214- */
215- @ Override
216- public void setIgnoreFailures (boolean ignoreFailures ) {
217- this .ignoreFailures = ignoreFailures ;
218- }
219-
220207 /**
221208 * The classes to validate.
222209 */
@@ -236,26 +223,29 @@ public ConfigurableFileCollection getClasspath() {
236223 }
237224
238225 /**
239- * Returns whether the build should break when the verifications performed by this task detects a warning.
226+ * Specifies whether the build should break when plugin verifications fails.
227+ *
228+ * @return {@code false} when the build should break on failure, {@code true} when failures should be ignored.
240229 */
241230 @ Input
242- public boolean getFailOnWarning () {
243- return failOnWarning ;
231+ public Property < Boolean > getIgnoreFailures () {
232+ return ignoreFailures ;
244233 }
245234
246235 /**
247- * Enable the stricter validation for cacheable tasks for all tasks .
236+ * Returns whether the build should break when the verifications performed by this task detects a warning .
248237 */
249238 @ Input
250- public boolean getEnableStricterValidation () {
251- return enableStricterValidation ;
239+ public Property < Boolean > getFailOnWarning () {
240+ return failOnWarning ;
252241 }
253242
254243 /**
255244 * Enable the stricter validation for cacheable tasks for all tasks.
256245 */
257- public void setEnableStricterValidation (boolean enableStricterValidation ) {
258- this .enableStricterValidation = enableStricterValidation ;
246+ @ Input
247+ public Property <Boolean > getEnableStricterValidation () {
248+ return enableStricterValidation ;
259249 }
260250
261251 /**
@@ -267,16 +257,6 @@ public RegularFileProperty getOutputFile() {
267257 return outputFile ;
268258 }
269259
270- /**
271- * Specifies whether the build should break when the verifications performed by this task detects a warning.
272- *
273- * @param failOnWarning {@code true} to break the build on warning, {@code false} to ignore warnings. The default is {@code true}.
274- */
275- @ SuppressWarnings ("unused" )
276- public void setFailOnWarning (boolean failOnWarning ) {
277- this .failOnWarning = failOnWarning ;
278- }
279-
280260 @ Inject
281261 protected ClassLoaderFactory getClassLoaderFactory () {
282262 throw new UnsupportedOperationException ();
0 commit comments