Skip to content

Commit e1f7b18

Browse files
committed
Clean up code complexity
Needs another major version bump due to aggressive API changes, especially in `AccessTransformerContainer`. Buildscript authors do not need to make any changes as Gradle generates the DSL for property setters.
1 parent 318fad3 commit e1f7b18

File tree

5 files changed

+72
-338
lines changed

5 files changed

+72
-338
lines changed

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersContainer.java

Lines changed: 29 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
import org.gradle.api.Action;
1313
import org.gradle.api.Project;
1414
import org.gradle.api.artifacts.Dependency;
15-
import org.gradle.api.artifacts.dsl.DependencyHandler;
1615
import org.gradle.api.attributes.Attribute;
16+
import org.gradle.api.file.ConfigurableFileCollection;
1717
import org.gradle.api.file.FileCollection;
18-
import org.gradle.api.file.RegularFile;
18+
import org.gradle.api.file.RegularFileProperty;
1919
import org.gradle.api.logging.LogLevel;
20+
import org.gradle.api.provider.ListProperty;
21+
import org.gradle.api.provider.Property;
2022
import org.gradle.api.provider.Provider;
2123
import org.gradle.api.provider.ProviderConvertible;
2224
import org.gradle.jvm.toolchain.JavaLauncher;
2325
import org.jetbrains.annotations.ApiStatus;
2426

25-
import java.io.File;
26-
import java.util.Arrays;
27-
import java.util.function.Function;
2827
import java.util.function.UnaryOperator;
2928

3029
/// Represents a container of dependencies that will be access transformed.
@@ -63,12 +62,11 @@ static AccessTransformersContainer register(Project project, Attribute<Boolean>
6362
/// @param dependencyNotation The dependency (notation)
6463
/// @param closure A configuring closure for the dependency
6564
/// @return The dependency to be transformed
66-
@SuppressWarnings("rawtypes") // public-facing closure
6765
Dependency dep(
6866
Object dependencyNotation,
6967
@DelegatesTo(Dependency.class)
7068
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
71-
Closure closure
69+
Closure<?> closure
7270
);
7371

7472
/// Queues the given dependency to be transformed by AccessTransformers.
@@ -93,12 +91,11 @@ default Dependency dep(Object dependencyNotation) {
9391
/// @param dependencyNotation The dependency (notation)
9492
/// @param closure A configuring closure for the dependency
9593
/// @return The dependency to be transformed
96-
@SuppressWarnings("rawtypes") // public-facing closure
9794
Provider<?> dep(
9895
Provider<?> dependencyNotation,
9996
@DelegatesTo(Dependency.class)
10097
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
101-
Closure closure
98+
Closure<?> closure
10299
);
103100

104101
/// Queues the given dependency to be transformed by AccessTransformers.
@@ -123,12 +120,11 @@ default Provider<?> dep(Provider<?> dependencyNotation) {
123120
/// @param dependencyNotation The dependency (notation)
124121
/// @param closure A configuring closure for the dependency
125122
/// @return The dependency to be transformed
126-
@SuppressWarnings("rawtypes") // public-facing closure
127123
default Provider<?> dep(
128124
ProviderConvertible<?> dependencyNotation,
129125
@DelegatesTo(Dependency.class)
130126
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
131-
Closure closure
127+
Closure<?> closure
132128
) {
133129
return this.dep(dependencyNotation.asProvider(), closure);
134130
}
@@ -153,223 +149,43 @@ default Provider<?> dep(ProviderConvertible<?> dependencyNotation) {
153149
/// When initially registering an AccessTransformers container, the consumer must define key information regarding
154150
/// how AccessTransformers will be used. This interface is used to define that information.
155151
sealed interface Options permits AccessTransformersContainerInternal.Options {
156-
/// Sets the AccessTransformer configuration to use.
152+
/// Gets the AccessTransformer configuration to use.
157153
///
158-
/// If the given provider does not provide a [file][File] or [regular file][RegularFile], the result will be
159-
/// resolved using [org.gradle.api.Project#file(Object)], similarly to [#setConfig(Object)].
160-
///
161-
/// @param configFile The configuration file to use
162-
void setConfig(Provider<?> configFile);
163-
164-
/// Sets the AccessTransformer configuration to use.
165-
///
166-
/// @param configFile The configuration file to use
167-
void setConfig(RegularFile configFile);
168-
169-
/// Sets the AccessTransformer configuration to use.
170-
///
171-
/// @param configFile The configuration file to use
172-
void setConfig(File configFile);
173-
174-
/// Sets the AccessTransformer configuration to use.
175-
///
176-
/// The given object is resolved using [org.gradle.api.Project#file(Object)].
177-
///
178-
/// @param configFile The configuration file to use
179-
void setConfig(Object configFile);
154+
/// @return The property for the configuration
155+
RegularFileProperty getConfig();
180156

181-
/// Sets the log level to pipe the output of AccessTransformers to.
157+
/// Gets the log level to pipe the output of AccessTransformers to.
182158
///
183-
/// @param level The log level to use
159+
/// @return The property log level to use
184160
/// @apiNote This is [experimental][ApiStatus.Experimental] due to the fact that AccessTransformers treats both
185161
/// [System#out] and [System#err] equally, while preferring to use the latter. This will be addressed in a
186162
/// future version of AccessTransformers.
187163
@ApiStatus.Experimental
188-
void setLogLevel(LogLevel level);
189-
190-
/// Sets the log level to pipe the output of AccessTransformers to.
191-
///
192-
/// @param level The log level to use
193-
/// @apiNote This is [experimental][ApiStatus.Experimental] due to the fact that AccessTransformers treats both
194-
/// [System#out] and [System#err] equally, while preferring to use the latter. This will be addressed in a
195-
/// future version of AccessTransformers.
196-
@ApiStatus.Experimental
197-
void setLogLevel(Provider<? extends LogLevel> level);
198-
199-
/// Sets the configuration to use as the classpath for AccessTransformers.
200-
///
201-
/// @param files The file collection to use
202-
void setClasspath(FileCollection files);
164+
Property<LogLevel> getLogLevel();
203165

204-
/// Sets the dependency to use as the classpath for AccessTransformers.
166+
/// Gets the classpath to use for AccessTransformers. By default, this contains the default AccessTransformers
167+
/// shadow JAR.
205168
///
206-
/// @param dependency The dependency to use
207-
void setClasspath(
208-
@DelegatesTo(value = DependencyHandler.class, strategy = Closure.DELEGATE_FIRST)
209-
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.dsl.DependencyHandler")
210-
Closure<? extends Dependency> dependency
211-
);
169+
/// @return The classpath
170+
/// @apiNote This is *not* the dependency's classpath. This is the classpath used in
171+
/// [org.gradle.process.JavaExecSpec#setClasspath(FileCollection)] to invoke AccessTransformers.
172+
ConfigurableFileCollection getClasspath();
212173

213-
/// Sets the dependency to use as the classpath for AccessTransformers.
174+
/// Gets the main class to invoke when running AccessTransformers.
214175
///
215-
/// @param dependency The dependency to use
216-
default void setClasspath(Function<? super DependencyHandler, ? extends Dependency> dependency) {
217-
this.setClasspath(Closures.function(this, dependency));
218-
}
176+
/// @return The property for the main class.
177+
/// @apiNote This is *not required* if the [classpath][#getClasspath()] is a single executable jar.
178+
Property<String> getMainClass();
219179

220-
/// Sets the dependency to use as the classpath for AccessTransformers.
221-
///
222-
/// @param dependencyNotation The dependency (notation) to use
223-
/// @param closure A configuring closure for the dependency
224-
@SuppressWarnings("rawtypes")
225-
default void setClasspath(
226-
Object dependencyNotation,
227-
@DelegatesTo(Dependency.class)
228-
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
229-
Closure closure
230-
) {
231-
this.setClasspath(dependencies -> dependencies.create(dependencyNotation, closure));
232-
}
233-
234-
/// Sets the dependency to use as the classpath for AccessTransformers.
235-
///
236-
/// @param dependencyNotation The dependency (notation) to use
237-
/// @param action A configuring action for the dependency
238-
default void setClasspath(
239-
Object dependencyNotation,
240-
Action<? super Dependency> action
241-
) {
242-
this.setClasspath(dependencyNotation, Closures.action(this, action));
243-
}
244-
245-
/// Sets the dependency to use as the classpath for AccessTransformers.
246-
///
247-
/// @param dependencyNotation The dependency (notation) to use
248-
default void setClasspath(Object dependencyNotation) {
249-
this.setClasspath(dependencyNotation, Closures.<Dependency>unaryOperator(this, UnaryOperator.identity()));
250-
}
251-
252-
/// Sets the dependency to use as the classpath for AccessTransformers.
253-
///
254-
/// @param dependencyNotation The dependency (notation) to use
255-
/// @param closure A configuring closure for the dependency
256-
@SuppressWarnings("rawtypes")
257-
default void setClasspath(
258-
Provider<?> dependencyNotation,
259-
@DelegatesTo(Dependency.class)
260-
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
261-
Closure closure
262-
) {
263-
this.setClasspath(dependencyNotation.get(), closure);
264-
}
265-
266-
/// Sets the dependency to use as the classpath for AccessTransformers.
267-
///
268-
/// @param dependencyNotation The dependency (notation) to use
269-
/// @param action A configuring action for the dependency
270-
default void setClasspath(
271-
Provider<?> dependencyNotation,
272-
Action<? super Dependency> action
273-
) {
274-
this.setClasspath(dependencyNotation, Closures.action(this, action));
275-
}
276-
277-
/// Sets the dependency to use as the classpath for AccessTransformers.
278-
///
279-
/// @param dependencyNotation The dependency (notation) to use
280-
default void setClasspath(Provider<?> dependencyNotation) {
281-
this.setClasspath(dependencyNotation, Closures.<Dependency>unaryOperator(this, UnaryOperator.identity()));
282-
}
283-
284-
/// Sets the dependency to use as the classpath for AccessTransformers.
285-
///
286-
/// @param dependencyNotation The dependency (notation) to use
287-
/// @param closure A configuring closure for the dependency
288-
@SuppressWarnings("rawtypes")
289-
default void setClasspath(
290-
ProviderConvertible<?> dependencyNotation,
291-
@DelegatesTo(Dependency.class)
292-
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.Dependency")
293-
Closure closure
294-
) {
295-
this.setClasspath(dependencyNotation.asProvider(), closure);
296-
}
297-
298-
/// Sets the dependency to use as the classpath for AccessTransformers.
299-
///
300-
/// @param dependencyNotation The dependency (notation) to use
301-
/// @param action A configuring action for the dependency
302-
default void setClasspath(
303-
ProviderConvertible<?> dependencyNotation,
304-
Action<? super Dependency> action
305-
) {
306-
this.setClasspath(dependencyNotation, Closures.action(this, action));
307-
}
308-
309-
/// Sets the dependency to use as the classpath for AccessTransformers.
310-
///
311-
/// @param dependencyNotation The dependency (notation) to use
312-
default void setClasspath(ProviderConvertible<?> dependencyNotation) {
313-
this.setClasspath(dependencyNotation, Closures.<Dependency>unaryOperator(this, UnaryOperator.identity()));
314-
}
315-
316-
/// Sets the main class to invoke when running AccessTransformers.
317-
///
318-
/// @param mainClass The main class to use
319-
/// @apiNote This is *not required* if the given [classpath][#setClasspath(FileCollection)] is a single
320-
/// executable jar.
321-
void setMainClass(Provider<String> mainClass);
322-
323-
/// Sets the main class to invoke when running AccessTransformers.
324-
///
325-
/// @param mainClass The main class to use
326-
/// @apiNote This is *not required* if the given [classpath][#setClasspath(FileCollection)] is a single
327-
/// executable jar.
328-
void setMainClass(String mainClass);
329-
330-
/// Sets the Java launcher to use to run AccessTransformers.
180+
/// Gets the Java launcher used to run AccessTransformers.
331181
///
332182
/// This can be easily acquired using [Java toolchains][org.gradle.jvm.toolchain.JavaToolchainService].
333183
///
334-
/// @param javaLauncher The Java launcher to use
184+
/// @return The property for the Java launcher
335185
/// @see org.gradle.jvm.toolchain.JavaToolchainService#launcherFor(Action)
336-
void setJavaLauncher(Provider<? extends JavaLauncher> javaLauncher);
337-
338-
/// Sets the Java launcher to use to run AccessTransformers.
339-
///
340-
/// This can be easily acquired using [Java toolchains][org.gradle.jvm.toolchain.JavaToolchainService].
341-
///
342-
/// @param javaLauncher The Java launcher to use
343-
/// @apiNote This method exists in case consumers have an eagerly processed `JavaLauncher` object. It is
344-
/// recommended to use [#setJavaLauncher(Provider)] instead.
345-
/// @see org.gradle.jvm.toolchain.JavaToolchainService#launcherFor(Action)
346-
void setJavaLauncher(JavaLauncher javaLauncher);
347-
348-
/// Sets the arguments to use when running AccessTransformers.
349-
///
350-
/// When processed by the transform action, these arguments will have specific tokens in them replaced.
351-
///
352-
/// - `{inJar}` - The input jar
353-
/// - `{atFile}` - The AccessTransformers configuration file
354-
/// - `{outJar}` - The output jar
355-
/// - `{logFile}` - The log file
356-
///
357-
/// @param args The arguments to use
358-
void setArgs(Provider<? extends Iterable<String>> args);
359-
360-
/// Sets the arguments to use when running AccessTransformers.
361-
///
362-
/// When processed by the transform action, these arguments will have specific tokens in them replaced.
363-
///
364-
/// - `{inJar}` - The input jar
365-
/// - `{atFile}` - The AccessTransformers configuration file
366-
/// - `{outJar}` - The output jar
367-
/// - `{logFile}` - The log file
368-
///
369-
/// @param args The arguments to use
370-
void setArgs(Iterable<String> args);
186+
Property<JavaLauncher> getJavaLauncher();
371187

372-
/// Sets the arguments to use when running AccessTransformers.
188+
/// Gets the list of arguments to use when running AccessTransformers.
373189
///
374190
/// When processed by the transform action, these arguments will have specific tokens in them replaced.
375191
///
@@ -378,9 +194,7 @@ default void setClasspath(ProviderConvertible<?> dependencyNotation) {
378194
/// - `{outJar}` - The output jar
379195
/// - `{logFile}` - The log file
380196
///
381-
/// @param args The arguments to use
382-
default void setArgs(String... args) {
383-
this.setArgs(Arrays.asList(args));
384-
}
197+
/// @return The property for the arguments.
198+
ListProperty<Object> getArgs();
385199
}
386200
}

0 commit comments

Comments
 (0)