Skip to content

Commit b630052

Browse files
committed
Fixed issues with Gradle property decoration
Any public or protected method that has the getter naming convention (getProperty) is decorated by Gradle when the class is instantiated. A lot of things in the shared package are largely internal and do not need modifications from Gradle, so they have been renamed without the "get" keyword to avoid that. For non-tasks, the `@Internal` annotation has no effect.
1 parent 79de92d commit b630052

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtensionImpl.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import static net.minecraftforge.gradleutils.GradleUtilsPlugin.LOGGER
3030

3131
final PomUtils pom
3232

33-
private ForProjectImpl(Project project) {
33+
@Inject
34+
ForProjectImpl(Project project) {
3435
this.project = project
3536

3637
this.pom = this.objects.newInstance(PomUtilsImpl, project)

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.gradle.api.model.ObjectFactory;
1313
import org.gradle.api.provider.Provider;
1414
import org.gradle.api.provider.ProviderFactory;
15+
import org.gradle.api.tasks.Internal;
1516
import org.jetbrains.annotations.ApiStatus;
1617

1718
import javax.inject.Inject;
@@ -44,7 +45,7 @@ public abstract class EnhancedPlugin<T> implements Plugin<T> {
4445

4546
/// This constructor must be called by all subclasses using a public constructor annotated with [Inject]. The name
4647
/// and display name passed in are used in a minimal instance of [EnhancedProblems], which is used to set up the
47-
/// plugin's [global][#getGlobalCaches()] and [local][#getLocalCaches()] caches. Additionally, the name is used to
48+
/// plugin's [global][#globalCaches()] and [local][#localCaches()] caches. Additionally, the name is used to
4849
/// create the cache folders (`minecraftforge/name`).
4950
///
5051
/// @param name The name for this plugin (must be machine-friendly)
@@ -70,11 +71,11 @@ public final void apply(T target) {
7071
public abstract void setup(T target);
7172

7273
/// Gets the target for this plugin. This will throw an exception if this is called before application (i.e. through
73-
/// early usage of [#getGlobalCaches()]).
74+
/// early usage of [#globalCaches()]).
7475
///
7576
/// @return The plugin target
7677
/// @throws RuntimeException If this plugin is not yet applied
77-
protected final T getTarget() {
78+
private T getTarget() {
7879
try {
7980
return Objects.requireNonNull(this.target);
8081
} catch (Exception e) {
@@ -96,7 +97,7 @@ final EnhancedProblems getProblemsInternal() {
9697
/// @return A provider for the tool file
9798
@SuppressWarnings("deprecation") // deprecation intentional, please use this method
9899
public Provider<File> getTool(Tool tool) {
99-
return tool.get(this.getGlobalCaches(), this.getProviders());
100+
return tool.get(this.globalCaches(), this.getProviders());
100101
}
101102

102103

@@ -112,7 +113,7 @@ public Provider<File> getTool(Tool tool) {
112113
/// @return The global caches
113114
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not [Project] or
114115
/// [org.gradle.api.initialization.Settings])
115-
public final DirectoryProperty getGlobalCaches() {
116+
public final DirectoryProperty globalCaches() {
116117
return this.globalCaches.get();
117118
}
118119

@@ -142,7 +143,7 @@ private DirectoryProperty makeGlobalCaches() {
142143
/// @return The global caches
143144
/// @throws RuntimeException If this plugin cannot access global caches (i.e. the target is not [Project] or
144145
/// [org.gradle.api.initialization.Settings])
145-
public final DirectoryProperty getLocalCaches() {
146+
public final DirectoryProperty localCaches() {
146147
return this.localCaches.get();
147148
}
148149

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.gradle.api.reflect.TypeOf;
2323
import org.jetbrains.annotations.ApiStatus;
2424
import org.jetbrains.annotations.Nullable;
25+
import org.jetbrains.annotations.VisibleForTesting;
2526

2627
import javax.inject.Inject;
2728
import java.io.IOException;
@@ -34,7 +35,7 @@
3435

3536
/// The enhanced problems contain several base helper members to help reduce duplicate code between Gradle plugins.
3637
@ApiStatus.OverrideOnly
37-
public abstract class EnhancedProblems implements Problems {
38+
public abstract class EnhancedProblems implements Problems, Predicate<String> {
3839
/// The common message to send in [ProblemSpec#solution(String)] when reporting problems.
3940
protected static final String HELP_MESSAGE = "Consult the documentation or ask for help on the Forge Forums, GitHub, or Discord server.";
4041

@@ -87,7 +88,7 @@ protected final ProblemId id(String name, String displayName) {
8788
///
8889
/// @param property The property to test
8990
/// @return If the property exists and is `true`
90-
protected final boolean hasProperty(String property) {
91+
public final boolean test(String property) {
9192
return this.properties.test(property);
9293
}
9394

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,26 @@ public interface EnhancedTask<T extends EnhancedPlugin<? super Project>> extends
1818
/// The enhanced plugin type for this task.
1919
///
2020
/// @return The plugin type
21-
@Internal
22-
Class<T> getPluginType();
21+
@Internal Class<T> getPluginType();
2322

2423
/// The enhanced plugin associated with this task.
2524
///
2625
/// @return The plugin
27-
@Internal
28-
default T getPlugin() {
26+
default @Internal T getPlugin() {
2927
return this.getProject().getPlugins().getPlugin(this.getPluginType());
3028
}
3129

3230
/// The default output directory to use for this task if it outputs a directory.
3331
///
3432
/// @return A provider for the directory
35-
@Internal
36-
default Provider<Directory> getDefaultOutputDirectory() {
37-
return this.getPlugin().getLocalCaches().dir(this.getName()).map(this.getPlugin().getProblemsInternal().ensureFileLocation());
33+
default @Internal Provider<Directory> getDefaultOutputDirectory() {
34+
return this.getPlugin().localCaches().dir(this.getName()).map(this.getPlugin().getProblemsInternal().ensureFileLocation());
3835
}
3936

4037
/// The default output file to use for this task if it outputs a file. Uses the `.jar` extension.
4138
///
4239
/// @return A provider for the file
43-
@Internal
44-
default Provider<RegularFile> getDefaultOutputFile() {
40+
default @Internal Provider<RegularFile> getDefaultOutputFile() {
4541
return this.getDefaultOutputFile("jar");
4642
}
4743

@@ -50,6 +46,6 @@ default Provider<RegularFile> getDefaultOutputFile() {
5046
/// @param ext The extension to use for the file
5147
/// @return A provider for the file
5248
default Provider<RegularFile> getDefaultOutputFile(String ext) {
53-
return this.getPlugin().getLocalCaches().file("%s/output.%s".formatted(this.getName(), ext)).map(this.getPlugin().getProblemsInternal().ensureFileLocation());
49+
return this.getPlugin().localCaches().file("%s/output.%s".formatted(this.getName(), ext)).map(this.getPlugin().getProblemsInternal().ensureFileLocation());
5450
}
5551
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected ToolExecBase(Class<P> problemsType, Tool tool) {
5151

5252
if (this instanceof EnhancedTask<?> enhancedTask) {
5353
this.defaultToolDir = this.getObjectFactory().directoryProperty().value(
54-
enhancedTask.getPlugin().getGlobalCaches().dir(tool.getName().toLowerCase(Locale.ENGLISH)).map(this.ensureFileLocationInternal())
54+
enhancedTask.getPlugin().globalCaches().dir(tool.getName().toLowerCase(Locale.ENGLISH)).map(this.ensureFileLocationInternal())
5555
);
5656
this.setClasspath(this.getObjectFactory().fileCollection().from(enhancedTask.getPlugin().getTool(tool)));
5757
} else {

0 commit comments

Comments
 (0)