Skip to content

Commit 229b993

Browse files
committed
Use Property<Boolean> in ValidatePlugins
1 parent 55edef2 commit 229b993

File tree

2 files changed

+28
-48
lines changed

2 files changed

+28
-48
lines changed

subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/tasks/ValidatePlugins.java

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.gradle.api.file.RegularFileProperty;
3535
import org.gradle.api.internal.DocumentationRegistry;
3636
import org.gradle.api.model.ObjectFactory;
37+
import org.gradle.api.provider.Property;
3738
import org.gradle.api.tasks.CacheableTask;
3839
import org.gradle.api.tasks.Classpath;
3940
import org.gradle.api.tasks.Input;
@@ -45,7 +46,6 @@
4546
import org.gradle.api.tasks.SkipWhenEmpty;
4647
import org.gradle.api.tasks.TaskAction;
4748
import org.gradle.api.tasks.TaskValidationException;
48-
import org.gradle.api.tasks.VerificationTask;
4949
import org.gradle.internal.classanalysis.AsmConstants;
5050
import org.gradle.internal.classloader.ClassLoaderFactory;
5151
import org.gradle.internal.classloader.ClassLoaderUtils;
@@ -76,19 +76,22 @@
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();

subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/tasks/ValidateTaskProperties.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public ValidateTaskProperties(TaskProvider<ValidatePlugins> delegate, Runnable d
8181
@Override
8282
public boolean getIgnoreFailures() {
8383
deprecationNagger.run();
84-
return delegate.get().getIgnoreFailures();
84+
return delegate.get().getIgnoreFailures().get();
8585
}
8686

8787
/**
@@ -90,7 +90,7 @@ public boolean getIgnoreFailures() {
9090
@Override
9191
public void setIgnoreFailures(boolean ignoreFailures) {
9292
deprecationNagger.run();
93-
delegate.get().setIgnoreFailures(ignoreFailures);
93+
delegate.get().getIgnoreFailures().set(ignoreFailures);
9494
}
9595

9696
/**
@@ -119,7 +119,7 @@ public ConfigurableFileCollection getClasspath() {
119119
@Internal
120120
public boolean getFailOnWarning() {
121121
deprecationNagger.run();
122-
return delegate.get().getFailOnWarning();
122+
return delegate.get().getFailOnWarning().get();
123123
}
124124

125125
/**
@@ -130,7 +130,7 @@ public boolean getFailOnWarning() {
130130
@Internal
131131
public boolean getEnableStricterValidation() {
132132
deprecationNagger.run();
133-
return delegate.get().getEnableStricterValidation();
133+
return delegate.get().getEnableStricterValidation().get();
134134
}
135135

136136
/**
@@ -140,7 +140,7 @@ public boolean getEnableStricterValidation() {
140140
*/
141141
public void setEnableStricterValidation(boolean enableStricterValidation) {
142142
deprecationNagger.run();
143-
delegate.get().setEnableStricterValidation(enableStricterValidation);
143+
delegate.get().getEnableStricterValidation().set(enableStricterValidation);
144144
}
145145

146146
/**
@@ -161,6 +161,6 @@ public RegularFileProperty getOutputFile() {
161161
*/
162162
public void setFailOnWarning(boolean failOnWarning) {
163163
deprecationNagger.run();
164-
delegate.get().setFailOnWarning(failOnWarning);
164+
delegate.get().getFailOnWarning().set(failOnWarning);
165165
}
166166
}

0 commit comments

Comments
 (0)