Skip to content

Commit 0a2fc1d

Browse files
committed
Cleanup and fix JavaDocs
1 parent 213fc22 commit 0a2fc1d

File tree

9 files changed

+132
-53
lines changed

9 files changed

+132
-53
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,54 @@
2222
/// The build failure is provided by [org.gradle.api.flow.FlowProviders#getBuildWorkResult()] mapped by
2323
/// [org.gradle.api.flow.BuildWorkResult#getFailure()].
2424
public abstract class EnhancedFlowAction<P extends EnhancedFlowAction.EnhancedFlowParameters<?>> implements FlowAction<P> {
25-
/// The parameters, including the [#getFailure()] property.
25+
/// The parameters, including the [#getFailure()] property and [EnhancedProblems] through [#problems()].
26+
///
27+
/// @param <P> The type of [EnhancedProblems] to use
2628
public static abstract class EnhancedFlowParameters<P extends EnhancedProblems> implements FlowParameters {
2729
private final Class<P> problemsType;
2830
private transient @Nullable P problems;
2931

3032
private final Property<Throwable> failure;
3133

34+
/// The object factory provided by Gradle services.
35+
///
36+
/// @return The object factory
37+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#objectfactory">ObjectFactory
38+
/// Service Injection</a>
3239
protected abstract @Inject ObjectFactory getObjects();
3340

41+
/// The base constructor for the parameters.
42+
///
43+
/// @param problemsType The type of enhanced problems that will be accessible through [#problems()].
44+
/// @implSpec Must override with `public` and `@`[Inject]
3445
protected EnhancedFlowParameters(Class<P> problemsType) {
3546
this.problemsType = problemsType;
3647

3748
this.failure = this.getObjects().property(Throwable.class);
3849
}
3950

51+
/// The enhanced problems to be accessed in [EnhancedFlowAction#run(EnhancedFlowParameters)]. They must be
52+
/// contained within the parameters as Gradle does not currently support injecting
53+
/// [org.gradle.api.problems.Problems] into flow actions.
54+
///
55+
/// @return The enhanced problems
56+
/// @see <a href="https://github.com/gradle/gradle/issues/33430">gradle#33430</a>
4057
public P problems() {
4158
return this.problems == null ? this.problems = this.getObjects().newInstance(this.problemsType) : this.problems;
4259
}
4360

61+
/// The failure that was thrown by Gradle. If the build did not fail, this property will not be
62+
/// [present][Property#isPresent()].
63+
///
64+
/// @return The property for the build failure
4465
public @Optional @Input Property<Throwable> getFailure() {
4566
return this.failure;
4667
}
4768
}
4869

70+
/// The base constructor for the flow action.
71+
///
72+
/// @implSpec Must override with `public` and `@`[Inject]
4973
protected EnhancedFlowAction() { }
5074

5175
/// Checks if a given throwable's [message][Throwable#getMessage()] contains the given string

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

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.gradle.api.model.ObjectFactory;
1515
import org.gradle.api.provider.Provider;
1616
import org.gradle.api.provider.ProviderFactory;
17-
import org.jetbrains.annotations.ApiStatus;
1817

1918
import javax.inject.Inject;
2019
import java.io.File;
@@ -24,29 +23,32 @@
2423
/// needing to duplicate code across projects.
2524
///
2625
/// @param <T> The type of target
27-
public abstract class EnhancedPlugin<T> implements Plugin<T> {
26+
public abstract class EnhancedPlugin<T> implements Plugin<T>, EnhancedPluginAdditions {
2827
private final String name;
2928
private final String displayName;
3029

3130
private T target;
3231
private final EnhancedProblems problemsInternal;
3332

34-
/**
35-
* @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#objectfactory">ObjectFactory
36-
* Service Injection</a>
37-
*/
33+
/// The object factory provided by Gradle services.
34+
///
35+
/// @return The object factory
36+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#objectfactory">ObjectFactory
37+
/// Service Injection</a>
3838
protected abstract @Inject ObjectFactory getObjects();
3939

40-
/**
41-
* @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#buildlayout">BuildLayout
42-
* Service Injection</a>
43-
*/
40+
/// The build layout provided by Gradle services.
41+
///
42+
/// @return The build layout
43+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#buildlayout">BuildLayout
44+
/// Service Injection</a>
4445
protected abstract @Inject BuildLayout getBuildLayout();
4546

46-
/**
47-
* @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#providerfactory">ProviderFactory
48-
* Service Injection</a>
49-
*/
47+
/// The provider factory provided by Gradle services.
48+
///
49+
/// @return The provider factory
50+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#providerfactory">ProviderFactory
51+
/// Service Injection</a>
5052
protected abstract @Inject ProviderFactory getProviders();
5153

5254
/// This constructor must be called by all subclasses using a public constructor annotated with [Inject]. The name
@@ -96,12 +98,8 @@ final EnhancedProblems getProblemsInternal() {
9698

9799
/* TOOLS */
98100

99-
/// Gets a provider to the file for a [Tool] to be used. The tool's state is managed by Gradle through the
100-
/// [org.gradle.api.provider.ValueSource] API and will not cause caching issues.
101-
///
102-
/// @param tool The tool to get
103-
/// @return A provider for the tool file
104101
@SuppressWarnings("deprecation") // deprecation intentional, please use this method
102+
@Override
105103
public Provider<File> getTool(Tool tool) {
106104
return tool.get(this.globalCaches(), this.getProviders());
107105
}
@@ -111,14 +109,7 @@ public Provider<File> getTool(Tool tool) {
111109

112110
private final Lazy<DirectoryProperty> globalCaches = Lazy.simple(this::makeGlobalCaches);
113111

114-
/// Gets the global caches to be used for this plugin. These caches persist between projects and should be used to
115-
/// eliminate excess work done by projects that request the same data.
116-
///
117-
/// It is stored in `~/.gradle/caches/minecraftforge/plugin`.
118-
///
119-
/// @return The global caches
120-
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not [Project] or
121-
/// [org.gradle.api.initialization.Settings])
112+
@Override
122113
public final DirectoryProperty globalCaches() {
123114
return this.globalCaches.get();
124115
}
@@ -141,14 +132,7 @@ private DirectoryProperty makeGlobalCaches() {
141132

142133
private final Lazy<DirectoryProperty> localCaches = Lazy.simple(this::makeLocalCaches);
143134

144-
/// Gets the local caches to be used for this plugin. Data done by tasks that should not be shared between projects
145-
/// should be stored here.
146-
///
147-
/// It is located in `project/build/minecraftforge/plugin`.
148-
///
149-
/// @return The global caches
150-
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not [Project] or
151-
/// [org.gradle.api.initialization.Settings])
135+
@Override
152136
public final DirectoryProperty localCaches() {
153137
return this.localCaches.get();
154138
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.minecraftforge.gradleutils.shared;
2+
3+
import org.gradle.api.file.DirectoryProperty;
4+
import org.gradle.api.provider.Provider;
5+
6+
import java.io.File;
7+
8+
/// This interface defines the additional methods added by [EnhancedPlugin]. They are additionally accessible in tasks
9+
/// that implement [EnhancedTask].
10+
public interface EnhancedPluginAdditions {
11+
/// Gets a provider to the file for a [Tool] to be used. The tool's state is managed by Gradle through the
12+
/// [org.gradle.api.provider.ValueSource] API and will not cause caching issues.
13+
///
14+
/// @param tool The tool to get
15+
/// @return A provider for the tool file
16+
Provider<File> getTool(Tool tool);
17+
18+
/// Gets the global caches to be used for this plugin. These caches persist between projects and should be used to
19+
/// eliminate excess work done by projects that request the same data.
20+
///
21+
/// It is stored in `~/.gradle/caches/minecraftforge/plugin`.
22+
///
23+
/// @return The global caches
24+
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not
25+
/// [org.gradle.api.Project] or [org.gradle.api.initialization.Settings])
26+
DirectoryProperty globalCaches();
27+
28+
/// Gets the local caches to be used for this plugin. Data done by tasks that should not be shared between projects
29+
/// should be stored here.
30+
///
31+
/// It is located in `project/build/minecraftforge/plugin`.
32+
///
33+
/// @return The global caches
34+
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not
35+
/// [org.gradle.api.Project] or [org.gradle.api.initialization.Settings])
36+
DirectoryProperty localCaches();
37+
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.gradle.api.provider.ProviderFactory;
2323
import org.gradle.api.reflect.HasPublicType;
2424
import org.gradle.api.reflect.TypeOf;
25-
import org.jetbrains.annotations.ApiStatus;
2625
import org.jetbrains.annotations.Nullable;
2726

2827
import javax.inject.Inject;
@@ -287,15 +286,19 @@ public TypeOf<?> getPublicType() {
287286

288287
/* IMPL INSTANTIATION */
289288

290-
/** @see <a href="https://docs.gradle.org/current/userguide/reporting_problems.html">Reporting Problems</a> */
289+
/// The problems instance provided by Gradle services.
290+
///
291+
/// @return The problems instance
292+
/// @see <a href="https://docs.gradle.org/current/userguide/reporting_problems.html">Reporting Problems</a>
291293
protected @Inject Problems getProblems() {
292294
throw new IllegalStateException();
293295
}
294296

295-
/**
296-
* @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#providerfactory">ProviderFactory
297-
* Service Injection</a>
298-
*/
297+
/// The provider factory provided by Gradle services.
298+
///
299+
/// @return The provider factory
300+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#providerfactory">ProviderFactory
301+
/// Service Injection</a>
299302
protected @Inject ProviderFactory getProviders() {
300303
throw new IllegalStateException();
301304
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@
1111
import org.gradle.api.file.RegularFile;
1212
import org.gradle.api.provider.Provider;
1313
import org.gradle.api.tasks.Internal;
14-
import org.jetbrains.annotations.VisibleForTesting;
1514

1615
import java.io.File;
1716

1817
/// The enhanced task contains a handful of helper methods to make working with the enhanced plugin and caches easier.
19-
public interface EnhancedTask extends Task {
18+
public interface EnhancedTask extends Task, EnhancedPluginAdditions {
2019
/// The enhanced plugin type for this task.
2120
///
2221
/// @return The plugin type
2322
Class<? extends EnhancedPlugin<? super Project>> pluginType();
2423

25-
@VisibleForTesting
24+
/// Gets the enhanced plugin used by this task as defined in [#pluginType()].
25+
///
26+
/// @return The enhanced plugin
27+
/// @deprecated This method is public only due to the limitations imposed by Java 8. Do not use this. Use
28+
/// [Task#getProject()] -> [org.gradle.api.plugins.PluginAware#getPlugins()] ->
29+
/// [org.gradle.api.plugins.PluginContainer#getPlugin(Class)].
30+
@Deprecated
31+
@SuppressWarnings("DeprecatedIsStillUsed")
2632
default @Internal EnhancedPlugin<? super Project> getPlugin() {
2733
return this.getProject().getPlugins().getPlugin(this.pluginType());
2834
}
2935

30-
/// @see EnhancedPlugin#getTool(Tool)
36+
@Override
3137
default Provider<File> getTool(Tool tool) {
3238
return this.getPlugin().getTool(tool);
3339
}
3440

35-
/// @see EnhancedPlugin#globalCaches()
41+
@Override
3642
default DirectoryProperty globalCaches() {
3743
return this.getPlugin().globalCaches();
3844
}
3945

40-
/// @see EnhancedPlugin#localCaches()
46+
@Override
4147
default DirectoryProperty localCaches() {
4248
return this.getPlugin().localCaches();
4349
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public boolean isPresent() {
142142
/// Copies this actionable lazy. This can be useful if you need to split off execution paths and have the same
143143
/// object with different mutations at a specific time.
144144
///
145-
/// @return The a new actionable lazy copied from this one
145+
/// @return A new actionable lazy copied from this one
146146
public Actionable<T> copy() {
147147
Actionable<T> ret = new Actionable<>(this.closure);
148148
ret.value = this.value;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.gradle.jvm.toolchain.JavaLauncher;
2323
import org.gradle.jvm.toolchain.JavaToolchainService;
2424
import org.gradle.jvm.toolchain.JavaToolchainSpec;
25+
import org.jetbrains.annotations.Contract;
2526

2627
import java.io.File;
2728
import java.io.OutputStream;
@@ -275,12 +276,29 @@ public static String toString(Dependency dependency) {
275276

276277
//region Properties
277278

279+
/// Makes a returning-self closure that finalizes a given property using [#finalizeProperty(Property)].
280+
///
281+
/// This is best used as the method argument for [org.codehaus.groovy.runtime.DefaultGroovyMethods#tap(Object,
282+
/// Closure)], which allows for in-lining property creation in Groovy code.
283+
///
284+
/// @param <P> The type of property to finalize
285+
/// @return The returning-self closure for finalizing a property
278286
public static <P extends Property<?>> Closure<P> finalizeProperty() {
279287
Closure<P> ret = Closures.unaryOperator(SharedUtil::finalizeProperty);
280288
ret.setResolveStrategy(Closure.DELEGATE_FIRST);
281289
return ret;
282290
}
283291

292+
/// Finalizes the given property to prevent any additional changes from being made to it.
293+
///
294+
/// This is done by simply calling [Property#disallowChanges()] and [Property#finalizeValueOnRead()]. These methods
295+
/// do not return the object itself, so this helper method exists to in-line property creation without needing to
296+
/// reference it again just to call these methods.
297+
///
298+
/// @param <P> The type of property to finalize
299+
/// @param property The property to finalize
300+
/// @return The property
301+
@Contract(value = "_ -> param1", mutates = "param1")
284302
public static <P extends Property<?>> P finalizeProperty(P property) {
285303
property.disallowChanges();
286304
property.finalizeValueOnRead();

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
/// consistent between plugins.
2626
///
2727
/// @param <P> The type of enhanced problems, used for common problems reporting with illegal task arguments
28+
/// @implSpec Implementing plugins should make a shared subclass named `ToolExec` which all other tool executing tasks
29+
/// should extend from.
2830
/// @see JavaExec
2931
/// @see Tool
3032
public abstract class ToolExecBase<P extends EnhancedProblems> extends JavaExec {
@@ -33,10 +35,11 @@ public abstract class ToolExecBase<P extends EnhancedProblems> extends JavaExec
3335
/// The default tool directory (usage is not required).
3436
protected final DirectoryProperty defaultToolDir;
3537

36-
/**
37-
* @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#sec:projectlayout">ProjectLayout
38-
* Service Injection</a>
39-
*/
38+
/// The project layout provided by Gradle services.
39+
///
40+
/// @return The project layout
41+
/// @see <a href="https://docs.gradle.org/current/userguide/service_injection.html#projectlayout">ProjectLayout
42+
/// Service Injection</a>
4043
protected abstract @Inject ProjectLayout getProjectLayout();
4144

4245
/// Creates a new task instance using the given types and tool information.
@@ -91,6 +94,8 @@ private <T extends FileSystemLocation> Transformer<T, T> ensureFileLocationInter
9194
@MustBeInvokedByOverriders
9295
protected void addArguments() { }
9396

97+
/// @implNote Not invoking this method from an overriding method *will* result in the tool never being executed and
98+
/// [#addArguments()] never being run.
9499
@Override
95100
public void exec() {
96101
if (this.getArgs().isEmpty())

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/package-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* that include Forge-specific helper methods.</p>
1010
**/
1111
@ApiStatus.Internal
12+
@NotNullByDefault
1213
package net.minecraftforge.gradleutils.shared;
1314

1415
import org.jetbrains.annotations.ApiStatus;
16+
import org.jetbrains.annotations.NotNullByDefault;

0 commit comments

Comments
 (0)