Skip to content

Commit 261a4a4

Browse files
committed
Additional helper methods for adding arguments in ToolExecBase
1 parent c0bcb23 commit 261a4a4

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

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

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
import org.gradle.api.tasks.Internal;
1717
import org.gradle.api.tasks.JavaExec;
1818
import org.gradle.api.tasks.Optional;
19+
import org.jetbrains.annotations.ApiStatus;
1920
import org.jetbrains.annotations.MustBeInvokedByOverriders;
20-
import org.jetbrains.annotations.Nullable;
21+
import org.jetbrains.annotations.UnknownNullability;
2122

2223
import javax.inject.Inject;
2324
import java.io.File;
24-
import java.util.Collections;
25-
import java.util.List;
2625
import java.util.Locale;
27-
import java.util.Objects;
26+
import java.util.Map;
2827

2928
/// This tool execution task is a template on top of [JavaExec] to make executing [tools][Tool] much easier and more
3029
/// consistent between plugins.
@@ -143,23 +142,52 @@ protected final void args(String arg, Iterable<? extends File> files) {
143142
/// @param arg The flag to use
144143
/// @param fileProvider The file to add
145144
protected final void args(String arg, FileSystemLocationProperty<? extends FileSystemLocation> fileProvider) {
146-
this.args(arg, fileProvider.getLocationOnly());
145+
this.args(arg, fileProvider, false);
146+
}
147+
148+
/// Adds the given argument followed by the given file location to the arguments.
149+
///
150+
/// @param arg The flag to use
151+
/// @param fileProvider The file to add
152+
protected final void args(String arg, FileSystemLocationProperty<? extends FileSystemLocation> fileProvider, boolean locationOnly) {
153+
this.args(arg, locationOnly ? fileProvider.getLocationOnly() : fileProvider);
147154
}
148155

149156
/// Adds the given argument followed by the given object (may be a file location) to the arguments.
150157
///
151158
/// @param arg The flag to use
152159
/// @param provider The object (or file) to add
153-
protected final void args(String arg, Provider<?> provider) {
154-
Object value = provider.map(it -> it instanceof FileSystemLocation ? ((FileSystemLocation) it).getAsFile() : it).get();
160+
protected final void args(String arg, @UnknownNullability Provider<?> provider) {
161+
if (provider == null || !provider.isPresent()) return;
155162

156-
this.args(arg, String.valueOf(value));
163+
// NOTE: We don't use File#getAbsoluteFile because path sensitivity should be handled by tasks.
164+
Object value = provider.map(it -> it instanceof FileSystemLocation ? ((FileSystemLocation) it).getAsFile() : it).getOrNull();
165+
if (value == null) return;
166+
167+
if (value instanceof Boolean && ((boolean) value))
168+
this.args(arg);
169+
else
170+
this.args(arg, String.valueOf(value));
171+
}
172+
173+
protected final void args(Map<?, ?> args) {
174+
for (Map.Entry<?, ?> entry : args.entrySet()) {
175+
Object key = entry.getKey();
176+
Object value = entry.getValue();
177+
this.args(
178+
key instanceof Provider ? ((Provider<?>) key).map(Object::toString).get() : this.getProviderFactory().provider(() -> key).map(Object::toString).get(),
179+
value instanceof Provider ? (Provider<?>) value : this.getProviderFactory().provider(() -> value)
180+
);
181+
}
157182
}
158183

159184
/// Adds the given argument if and only if the given boolean property is [present][Provider#isPresent()] and true.
160185
///
161186
/// @param arg The argument to add
162187
/// @param onlyIf The provider to test
188+
/// @deprecated Use [#args(String, Provider)].
189+
@Deprecated
190+
@ApiStatus.ScheduledForRemoval
163191
protected final void argOnlyIf(String arg, Provider<Boolean> onlyIf) {
164192
this.argOnlyIf(arg, task -> onlyIf.isPresent() && onlyIf.getOrElse(false));
165193
}
@@ -168,6 +196,9 @@ protected final void argOnlyIf(String arg, Provider<Boolean> onlyIf) {
168196
///
169197
/// @param arg The argument to add
170198
/// @param onlyIf The spec to test
199+
/// @deprecated Use [#args(String, Provider)].
200+
@Deprecated
201+
@ApiStatus.ScheduledForRemoval
171202
protected final void argOnlyIf(String arg, Spec<? super ToolExecBase<?>> onlyIf) {
172203
if (onlyIf.isSatisfiedBy(this))
173204
this.args(arg);

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsProblems.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ RuntimeException pomUtilsGitVersionMissing(Exception e) {
4545
.solution("Manually add the remote URL in `addRemoteDetails`.")
4646
.solution(HELP_MESSAGE));
4747
}
48-
49-
void reportPomUtilsForgeProjWithoutForgeOrg() {
50-
this.getReporter().report(id("pomutils-forge-proj-missing-forge-org", "Detected Forge project is missing Forge organization details"), spec -> spec
51-
.details("""
52-
This project was autodetected as a MinecraftForge project, but `gradleutils.pom.addForgeDetails` was not used.""")
53-
.severity(Severity.ADVICE)
54-
.stackLocation()
55-
.solution("Consider using `gradleutils.pom.addForgeDetails`."));
56-
}
5748
//endregion
5849

5950
//region JavaDoc Links

0 commit comments

Comments
 (0)