Skip to content

Commit 8bbe826

Browse files
committed
Finalize API and define clear limitations
In order to play nice with Gradle's design and the concept of reproduceable builds, I've decided to set a limit on how much the API can help consumers with. Moving forward, there are two clearly defined ways you can use this plugin: 1. Use the API, which is quicker and does a lot of set up. The trade-off is that it is limited to using incoming dependency subtitutions, which can be problematic for complex setups. 2. Use the `ArtifactAccessTransformer` artifact transform class, which is public. Advanced Gradle users can use the transformer how they see fit. JavaDocs have been written to help with its usage, and the responsibility of how it is used rests solely on them. Additionally, here are some following rules when defining dependencies to be queued: - Dependencies *must* have a version specified, as per the requirement of dependency subtitutions. - Dependency constraints can be unversioned *if and only if* there exists a (transitive) dependency that can fulfill it.
1 parent be8fe04 commit 8bbe826

10 files changed

+282
-103
lines changed

at-gradle-demo/build.gradle

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ group = 'net.minecraftforge'
99
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
1010

1111
dependencies {
12-
implementation(libs.coremods) {
13-
accessTransformers.configure(it) {
14-
config = project.file('accesstransformer.cfg')
12+
constraints {
13+
// This can be used on transitive dependencies without actually adding them to your project's dependency tree.
14+
// While they are added to the module metadata, they don't have any attributes.
15+
implementation('net.minecraftforge:coremods') {
16+
accessTransformers.configure(it) {
17+
config = project.file('accesstransformer.cfg')
18+
}
1519
}
1620
}
1721

22+
implementation(libs.coremods)
23+
1824
compileOnly libs.log4j.api
1925
}
2026

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,50 @@
44
*/
55
package net.minecraftforge.accesstransformers.gradle;
66

7+
import org.gradle.api.plugins.ExtensionAware;
8+
import org.gradle.api.plugins.ExtraPropertiesExtension;
79
import org.gradle.api.reflect.HasPublicType;
810
import org.gradle.api.reflect.TypeOf;
911

12+
import java.util.LinkedList;
13+
import java.util.List;
14+
import java.util.Objects;
15+
1016
non-sealed interface AccessTransformersConfigurationInternal extends AccessTransformersConfiguration, HasPublicType {
17+
String CONFIGS_EXT_PROPERTY = "__accessTransformers_configs";
18+
19+
static boolean has(Object object) {
20+
try {
21+
return ((ExtensionAware) object).getExtensions().getExtraProperties().has(CONFIGS_EXT_PROPERTY);
22+
} catch (Exception e) {
23+
return false;
24+
}
25+
}
26+
27+
@SuppressWarnings("unchecked")
28+
static List<AccessTransformersConfigurationInternal> get(Object object) {
29+
ExtraPropertiesExtension ext;
30+
try {
31+
ext = ((ExtensionAware) object).getExtensions().getExtraProperties();
32+
} catch (Exception e) {
33+
// TODO [AccessTransformers][Gradle] Make problem for this
34+
throw new RuntimeException("Failed to get extension for " + object, e);
35+
}
36+
37+
try {
38+
return (List<AccessTransformersConfigurationInternal>) Objects.requireNonNull(
39+
ext.get(CONFIGS_EXT_PROPERTY),
40+
"Configs ext property should never be null!"
41+
);
42+
} catch (ExtraPropertiesExtension.UnknownPropertyException e) {
43+
var ret = new LinkedList<AccessTransformersConfigurationInternal>();
44+
ext.set(CONFIGS_EXT_PROPERTY, ret);
45+
return ret;
46+
}
47+
}
48+
49+
AccessTransformersContainerInternal.Options options();
50+
1151
@Override
1252
default TypeOf<?> getPublicType() {
1353
return TypeOf.typeOf(AccessTransformersConfiguration.class);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ default void configure(Object dependency) {
4545
/// Configures the given dependency to use this AccessTransformers container.
4646
///
4747
/// @param dependency The dependency to configure AccessTransformers for
48-
/// @param action A configuring action to modify dependency-level AccessTransformer options
48+
/// @param action A configuring action to modify dependency-level AccessTransformer options
4949
void configure(Object dependency, Action<? super AccessTransformersConfiguration> action);
5050

5151
/// When initially registering an AccessTransformers container, the consumer should define key information regarding

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
import org.gradle.api.file.RegularFileProperty;
1111
import org.gradle.api.logging.LogLevel;
1212
import org.gradle.api.model.ObjectFactory;
13-
import org.gradle.api.plugins.ExtensionAware;
1413
import org.gradle.api.provider.ListProperty;
1514
import org.gradle.api.provider.Property;
1615
import org.gradle.jvm.toolchain.JavaLauncher;
1716

1817
import javax.inject.Inject;
19-
import java.util.LinkedList;
20-
import java.util.List;
2118

2219
abstract class AccessTransformersContainerImpl implements AccessTransformersContainerInternal {
2320
private final OptionsImpl options;
@@ -39,18 +36,10 @@ public AccessTransformersContainer.Options getOptions() {
3936

4037
@Override
4138
public void configure(Object dependency, Action<? super AccessTransformersConfiguration> action) {
42-
var ext = ((ExtensionAware) dependency).getExtensions().getExtraProperties();
43-
var attributes = ext.has("__accessTransformers_configs")
44-
? (List<AccessTransformersConfigurationImpl>) ext.get("__accessTransformers_configs")
45-
: null;
46-
if (attributes == null) {
47-
attributes = new LinkedList<>();
48-
ext.set("__accessTransformers_configs", attributes);
49-
}
50-
5139
var config = new AccessTransformersConfigurationImpl(this.getObjects().fileProperty().convention(this.options.config), this.options);
5240
action.execute(config);
53-
attributes.add(config);
41+
42+
AccessTransformersConfigurationInternal.get(dependency).add(config);
5443
}
5544

5645
static abstract class OptionsImpl implements Options {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
package net.minecraftforge.accesstransformers.gradle;
66

77
import org.gradle.api.Action;
8-
import org.gradle.api.DomainObjectSet;
9-
import org.gradle.api.NamedDomainObjectProvider;
108
import org.gradle.api.Project;
11-
import org.gradle.api.artifacts.DependencyScopeConfiguration;
129
import org.gradle.api.reflect.HasPublicType;
1310
import org.gradle.api.reflect.TypeOf;
1411

0 commit comments

Comments
 (0)