Skip to content

Commit c4fdb44

Browse files
committed
Expose a way to use generated mixin mappings
1 parent 0ec173f commit c4fdb44

File tree

8 files changed

+72
-15
lines changed

8 files changed

+72
-15
lines changed

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/MergeMappings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ protected void exec() throws IOException {
5353
// I am specifically forcing this to be a single file to go along with other tasks
5454
// And because ConfigurableFileCollections use a set which is unordered and order matters
5555
var file = cfg.getSingleFile();
56+
// Sometimes we get files that don't exist, from Mixin bullshit
57+
if (!file.exists())
58+
continue;
59+
5660
var current = IMappingFile.load(file);
5761
if (map == null)
5862
map = current;

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/MixinConfig.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,38 @@ default MixinSourceSetConfig source(SourceSet source, String name) {
7272
*/
7373
MixinSourceSetConfig source(SourceSet source, String name, Action<? super MixinSourceSetConfig> action);
7474

75+
/**
76+
* <pre>Adds The following to the specified ForgeGradle run config:
77+
* Args:
78+
* {@code "--mixin-config [config]"} - Tells Mixin to load specific configs, this is not needed if you specify hem in your Manifest file
79+
* System Properties:
80+
* {@code "mixin.env.remapRefMap: true"} - Tells Mixin to remap refmaps when loading
81+
* {@code "mixin.env.refMapremappingFile: [map file]"} - The mapping file used to generate the refmap
82+
*
83+
* @param runConfig
84+
* </pre>
85+
*/
7586
void run(Object runConfig);
87+
88+
/**
89+
* <pre>Configures a Jar task with Mixin related values.
90+
* Specifically it adds a Manifest entry called {@code MixinConfigs} with a comma separated list of config files.
91+
* It also forces the inclusion of any refMap files for registered sourcesets
92+
*
93+
* @param provider The jar task provider
94+
* </pre>
95+
*/
7696
void jar(TaskProvider<Jar> provider);
97+
98+
/**
99+
* Gets the task that merges all generated extra mappings merged together.
100+
*/
101+
TaskProvider<MergeMappings> getGeneratedMappings();
102+
103+
/**
104+
* Gets the task that converts a mapping file into the format needed by the Annotation Processor
105+
* This can be used to customize what mappings are applied.
106+
* Defaults to converting {@link RenamerExtension#getMappings()} to {@code `tsrg`}
107+
*/
108+
TaskProvider<ConvertMappings> getMappings();
77109
}

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/MixinConfigImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ abstract class MixinConfigImpl implements MixinConfig {
2424
private static final Logger LOGGER = LogManager.getLogger(MixinConfig.class);
2525
private final RenamerExtensionImpl ext;
2626
private final Map<String, MixinSourceSetConfigImpl> sourceSets = new HashMap<>();
27+
private final TaskProvider<ConvertMappings> formatMappings;
28+
private final TaskProvider<MergeMappings> generatedMappings;
2729

2830
@Inject
2931
public MixinConfigImpl(RenamerExtensionImpl ext) {
3032
this.ext = ext;
3133
this.getMappingTypes().convention(List.of("tsrg"));
34+
this.formatMappings = ext.convert("formatMixinMappings", null, "tsrg", task -> task.map(ext.mappings));
35+
this.generatedMappings = ext.merge("mergeMixinMappings", task -> task.map(this.formatMappings));
3236

3337
/*
3438
* Mixin Magic:
@@ -62,6 +66,16 @@ public MixinConfigImpl(RenamerExtensionImpl ext) {
6266
*/
6367
}
6468

69+
@Override
70+
public TaskProvider<MergeMappings> getGeneratedMappings() {
71+
return this.generatedMappings;
72+
}
73+
74+
@Override
75+
public TaskProvider<ConvertMappings> getMappings() {
76+
return this.formatMappings;
77+
}
78+
6579
@Override
6680
public MixinSourceSetConfig source(SourceSet source, String name, Action<? super MixinSourceSetConfig> action) {
6781
if (this.sourceSets.containsKey(source.getName()))
@@ -85,7 +99,7 @@ public void run(Object runConfig) {
8599
return ret;
86100
}));
87101
//InvokerHelper.invokeMethod(runConfig, "systemProperty", new String[]{"mixin.env.disableRefMap", "true"});
88-
InvokerHelper.invokeMethod(runConfig, "systemProperties", this.ext.mixinMappings.flatMap(task -> task.getOutput()).map(
102+
InvokerHelper.invokeMethod(runConfig, "systemProperties", this.generatedMappings.flatMap(task -> task.getOutput()).map(
89103
file -> Map.of(
90104
"mixin.env.remapRefMap", "true",
91105
"mixin.env.refMapRemappingFile", file.getAsFile().getAbsolutePath()

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/MixinSourceSetConfigImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public MixinSourceSetConfigImpl(RenamerExtensionImpl ext, MixinConfigImpl main,
5252
sourceExt.set("refMapFile", refMapFile);
5353

5454
compile.configure(task -> {
55-
var mappings = ext.mixinMappings.flatMap(ConvertMappings::getOutput);
55+
var mappings = main.getMappings().flatMap(ConvertMappings::getOutput);
5656
task.getInputs().files(mappings);
5757
// These are generated by the AP
5858
var extra = task.getExtensions().getExtraProperties();
@@ -63,6 +63,9 @@ public MixinSourceSetConfigImpl(RenamerExtensionImpl ext, MixinConfigImpl main,
6363
project.getObjects().newInstance(CompilerArgs.class, MixinSourceSetConfigImpl.this, task, mappings)
6464
);
6565
});
66+
67+
// Add our output mappings to the merge task
68+
main.getGeneratedMappings().configure(task -> task.map(mappingFile));
6669
}
6770

6871
abstract static class CompilerArgs implements CommandLineArgumentProvider {

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/RenameJar.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,13 @@ public abstract class RenameJar extends ToolExecBase<RenamerProblems> implements
5656
protected abstract @Inject DependencyFactory getDependencyFactory();
5757

5858
@Inject
59-
public RenameJar() {
59+
public RenameJar(RenamerExtensionImpl renamer) {
6060
super(Tools.RENAMER);
6161
// We don't want the default runs to log to the main task output
6262
this.getStandardOutputLogLevel().convention(LogLevel.INFO);
6363

6464
// As a reminder, this is overridden by manually calling one of the #mappings methods
65-
this.getMap().convention(getProviders().provider(() -> {
66-
// TODO [Renamer] This assumes there's only ever one registered renamer, but i don't care for now
67-
var renamer = (RenamerExtensionImpl) getProject().getExtensions().findByType(RenamerExtension.class);
68-
if (renamer == null) return null;
69-
70-
return renamer.mappings;
71-
}));
65+
this.getMap().convention(getProviders().provider(() -> renamer.mappings));
7266

7367
this.getOutput().convention(
7468
getObjects().fileProperty().fileProvider(getProviders().zip(this.getInput().getLocationOnly(), this.getArchiveClassifier().orElse(""), (input, classifier) -> {

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/RenamerExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.codehaus.groovy.runtime.StringGroovyMethods;
88
import org.gradle.api.Action;
99
import org.gradle.api.artifacts.Dependency;
10+
import org.gradle.api.file.ConfigurableFileCollection;
1011
import org.gradle.api.file.FileCollection;
1112
import org.gradle.api.provider.Provider;
1213
import org.gradle.api.provider.ProviderConvertible;
@@ -36,6 +37,8 @@ default void mappings(ProviderConvertible<?> dependency) {
3637

3738
void setMappings(FileCollection files);
3839

40+
ConfigurableFileCollection getMappings();
41+
3942
default TaskProvider<RenameJar> classes(AbstractArchiveTask input) {
4043
return this.classes(input, it -> it.from(input));
4144
}

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/RenamerExtensionImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ abstract class RenamerExtensionImpl implements RenamerExtensionInternal {
2727
final ConfigurableFileCollection mappings = getObjects().fileCollection();
2828
private int dependencyCount = 0;
2929
boolean defaultMixinBehavior = true;
30-
MixinConfigImpl mixin = null;
31-
TaskProvider<ConvertMappings> mixinMappings = null;
30+
private MixinConfigImpl mixin = null;
3231

3332
protected abstract @Inject Project getProject();
3433

@@ -67,11 +66,17 @@ public void setMappings(FileCollection files) {
6766
this.mappings.setFrom(files);
6867
}
6968

69+
@Override
70+
public ConfigurableFileCollection getMappings() {
71+
return this.mappings;
72+
}
73+
7074
private static final String ASSEMBLE = "assemble";
7175
@Override
7276
public TaskProvider<RenameJar> classes(String name, Action<? super RenameJar> action) {
7377
var tasks = getProject().getTasks();
74-
var ret = tasks.register(name, RenameJar.class, action);
78+
var ret = tasks.register(name, RenameJar.class, this);
79+
ret.configure(action);
7580

7681
// Make the assemble task build our file, like the normal java plugin does
7782
if (tasks.getNames().contains(ASSEMBLE))
@@ -121,7 +126,8 @@ public Provider<Dependency> dependency(String notation, Action<? super RenameJar
121126
self.setTransitive(false);
122127
var deps = this.getProject().getConfigurations().detachedConfiguration(dep);
123128
var libraries = deps.minus(self);
124-
var rename = this.getProject().getTasks().register("_rename_dep_" + this.dependencyCount++, RenameJar.class, task -> {
129+
var rename = this.getProject().getTasks().register("_rename_dep_" + this.dependencyCount++, RenameJar.class, this);
130+
rename.configure(task -> {
125131
task.getMap().setFrom(this.mappings);
126132
task.getInput().set(self.getSingleFile());
127133
task.getLibraries().setFrom(libraries);
@@ -134,7 +140,6 @@ public Provider<Dependency> dependency(String notation, Action<? super RenameJar
134140
public MixinConfig getMixin() {
135141
if (this.mixin == null) {
136142
this.mixin = this.getObjects().newInstance(MixinConfigImpl.class, this);
137-
this.mixinMappings = this.convert("mixinMappings", null, "tsrg", task -> task.map(this.mappings));
138143
this.getProject().afterEvaluate(this::mixinDefaultActions);
139144
}
140145
return this.mixin;

renamer-gradle/src/main/java/net/minecraftforge/renamer/gradle/Util.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static Configuration toConfiguration(Project project, Provider<?> input) {
3737
ret.getDependencies().addLater(input.map(value -> {
3838
if (value instanceof Dependency dep)
3939
return dep;
40+
if (value instanceof File file)
41+
return deps.create(project.files(file));
4042
return deps.create(value);
4143
}));
4244
return ret;

0 commit comments

Comments
 (0)