Skip to content

Commit 0d2cde6

Browse files
committed
Cleaned up internal problem reporting
1 parent 0e03d25 commit 0d2cde6

File tree

3 files changed

+27
-47
lines changed

3 files changed

+27
-47
lines changed

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/Closures.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ public static Closure<Void> empty(Object owner) {
248248
}
249249

250250
private static final class Functional<T, R> extends Closure<R> {
251+
private static final long serialVersionUID = -8736820647200105725L;
252+
251253
private final Function<? super T, ? extends R> function;
252254

253255
private Functional(Object owner, Function<? super T, ? extends R> function) {
@@ -262,6 +264,8 @@ public R doCall(T object) {
262264
}
263265

264266
private static final class Supplying<R> extends Closure<R> {
267+
private static final long serialVersionUID = 1281109313872080614L;
268+
265269
private final Callable<? extends R> supplier;
266270

267271
private Supplying(Object owner, Callable<? extends R> supplier) {
@@ -276,6 +280,8 @@ public R doCall() throws Exception {
276280
}
277281

278282
private static final class Consuming<T> extends Closure<Void> {
283+
private static final long serialVersionUID = 1165200476195312981L;
284+
279285
private final Consumer<? super T> consumer;
280286

281287
private Consuming(Object owner, Consumer<? super T> consumer) {
@@ -291,6 +297,8 @@ public Void doCall(T object) {
291297
}
292298

293299
private static final class Running extends Empty {
300+
private static final long serialVersionUID = -3453835628821302135L;
301+
294302
private final Runnable runnable;
295303

296304
private Running(Object owner, Runnable runnable) {
@@ -306,7 +314,9 @@ public Void doCall() {
306314
}
307315

308316
private static class Empty extends Closure<Void> {
309-
public Empty(Object owner) {
317+
private static final long serialVersionUID = 6072707343050307552L;
318+
319+
private Empty(Object owner) {
310320
super(owner, owner);
311321
}
312322

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/EnhancedProblems.java

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package net.minecraftforge.gradleutils.shared;
66

7-
import groovy.lang.GroovyObjectSupport;
87
import org.gradle.api.Action;
98
import org.gradle.api.Task;
109
import org.gradle.api.Transformer;
@@ -31,6 +30,7 @@
3130
import java.io.Serializable;
3231
import java.nio.file.Files;
3332
import java.util.Collection;
33+
import java.util.Locale;
3434
import java.util.function.Predicate;
3535
import java.util.stream.Collectors;
3636
import java.util.stream.Stream;
@@ -136,15 +136,8 @@ public final boolean test(String property) {
136136
/* DEFAULT PROBLEMS */
137137

138138
//region Enhanced Plugin
139-
140-
/// Reports an illegal plugin target.
141-
///
142-
/// @param e The exception that was caught, will be re-thrown (or wrapped with a
143-
/// [RuntimeException])
144-
/// @param firstAllowedTarget The first allowed target for the plugin
145-
/// @param allowedTargets The remaining allowed targets for the plugin
146-
/// @return The exception to throw
147-
public final RuntimeException illegalPluginTarget(Exception e, Class<?> firstAllowedTarget, Class<?>... allowedTargets) {
139+
@SuppressWarnings("SameParameterValue")
140+
final RuntimeException illegalPluginTarget(Exception e, Class<?> firstAllowedTarget, Class<?>... allowedTargets) {
148141
return this.getReporter().throwing(e, id("invalid-plugin-target", "Invalid plugin target"), spec -> spec
149142
.details(String.format(
150143
"Attempted to apply the %s plugin to an invalid target.\n" +
@@ -156,12 +149,8 @@ public final RuntimeException illegalPluginTarget(Exception e, Class<?> firstAll
156149
.solution(HELP_MESSAGE));
157150
}
158151

159-
/// Reports an illegal plugin target.
160-
///
161-
/// @param e The exception that was caught, will be re-thrown (or wrapped with a [RuntimeException])
162-
/// @param allowedTargets A string stating the allowed targets for the plugin
163-
/// @return The exception to throw
164-
public final RuntimeException illegalPluginTarget(Exception e, String allowedTargets) {
152+
@SuppressWarnings("SameParameterValue")
153+
final RuntimeException illegalPluginTarget(Exception e, String allowedTargets) {
165154
return this.getReporter().throwing(e, id("invalid-plugin-target", "Invalid plugin target"), spec -> spec
166155
.details(String.format(
167156
"Attempted to apply the %s plugin to an invalid target.\n" +
@@ -172,11 +161,7 @@ public final RuntimeException illegalPluginTarget(Exception e, String allowedTar
172161
.solution(HELP_MESSAGE));
173162
}
174163

175-
/// Reports an illegal access of a plugin before it has been applied.
176-
///
177-
/// @param e The exception that was caught, will be re-thrown (or wrapped with a [RuntimeException])
178-
/// @return The exception to throw
179-
public final RuntimeException pluginNotYetApplied(Exception e) {
164+
final RuntimeException pluginNotYetApplied(Exception e) {
180165
return this.getReporter().throwing(e, id("plugin-not-yet-applied", String.format("%s is not applied", this.displayName)), spec -> spec
181166
.details(String.format(
182167
"Attempted to get details from the %s plugin, but it has not yet been applied to the target.", this.displayName))
@@ -190,39 +175,23 @@ public final RuntimeException pluginNotYetApplied(Exception e) {
190175
//endregion
191176

192177
//region ToolExecBase
193-
194-
/// Reports an implementation of [ToolExecBase] that is not enhanced with [EnhancedTask].
195-
///
196-
/// @param task The affected task
197-
public final void reportToolExecNotEnhanced(Task task) {
198-
this.getReporter().report(id("tool-exec-not-enhanced", "ToolExec subclass doesn't implement EnhancedTask"), spec -> spec
178+
final void reportToolExecNotEnhanced(Task task) {
179+
String className = task.getClass().getSimpleName().replace('.', '-');
180+
task.getLogger().warn("WARNING: {} doesn't implement EnhancedTask", className);
181+
this.getReporter().report(id(String.format("%s-not-enhanced", className.toLowerCase(Locale.ROOT)), String.format("%s doesn't implement EnhancedTask", className)), spec -> spec
199182
.details(String.format(
200-
"Implementing subclass of ToolExecBase should also implement (a subclass of) EnhancedTask.\n" +
183+
"Implementing subclasses of ToolExecBase should also implement (a subclass of) EnhancedTask.\n" +
201184
"Not doing so will result in global caches being ignored. Please check your implementations.\n" +
202185
"Affected task: %s (%s)", task, task.getClass()))
203186
.severity(Severity.WARNING)
204187
.stackLocation()
205188
.solution("Double check your task implementation."));
206189
}
207190

208-
/// Reports an implementation of [EnhancedTask] that does not implement [EnhancedTask#pluginType()]
209-
///
210-
/// @param task The affected task
211-
public final void reportToolExecNotEnhanced(Class<?> task) {
212-
this.getReporter().report(id("enhanced-task-no-plugin", "EnhancedTask doesn't implement #pluginType"), spec -> spec
213-
.details(String.format(
214-
"Implementation of EnhancedTask must implement #pluginType\n" +
215-
"Affected task type: %s", task))
216-
.severity(Severity.ERROR)
217-
.stackLocation()
218-
.solution("Double check your task implementation."));
219-
}
220-
221-
/// Reports an implementation of [ToolExecBase] that adds arguments without using [ToolExecBase#addArguments()]
222-
///
223-
/// @param task The affected task
224-
public final void reportToolExecEagerArgs(Task task) {
225-
this.getReporter().report(id("tool-exec-eager-args", "ToolExecBase implementation adds arguments without using addArguments()"), spec -> spec
191+
final void reportToolExecEagerArgs(Task task) {
192+
String className = task.getClass().getSimpleName().replace('.', '-');
193+
task.getLogger().warn("WARNING: {} implementation adds arguments without using addArguments()", className);
194+
this.getReporter().report(id(String.format("%s-eager-args", className.toLowerCase(Locale.ROOT)), String.format("%s implementation adds arguments without using addArguments()", className)), spec -> spec
226195
.details(String.format(
227196
"A ToolExecBase task is eagerly adding arguments using JavaExec#args without using ToolExecBase#addArguments.\n" +
228197
"This may cause implementations or superclasses to have their arguments ignored or missing.\n" +

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/ToolImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class ToolImpl implements Tool {
2525
private static final long serialVersionUID = -862411638019629688L;
26+
2627
private static final Logger LOGGER = Logging.getLogger(Tool.class);
2728

2829
private final String name;

0 commit comments

Comments
 (0)