mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
Support Mixin 0.8.5's configurable AP message levels.
Same API as MixinGradle. Closes #671
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
package net.fabricmc.loom.api;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.provider.MapProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.util.PatternSet;
|
||||
@@ -38,6 +39,10 @@ public interface MixinExtensionAPI {
|
||||
|
||||
Property<String> getRefmapTargetNamespace();
|
||||
|
||||
MapProperty<String, String> getMessages();
|
||||
|
||||
Property<Boolean> getShowMessageTypes();
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet.
|
||||
* @param sourceSet the sourceSet that applies Mixin AP.
|
||||
@@ -95,4 +100,6 @@ public interface MixinExtensionAPI {
|
||||
* @param sourceSetName the name of sourceSet that applies Mixin AP.
|
||||
*/
|
||||
void add(String sourceSetName);
|
||||
|
||||
void messages(Action<MapProperty<String, String>> action);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
@@ -56,7 +58,11 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
public static final String SCALA = "scala";
|
||||
public static final String GROOVY = "groovy";
|
||||
|
||||
private static final Pattern MSG_KEY_PATTERN = Pattern.compile("^[A-Z]+[A-Z_]+$");
|
||||
private static final Pattern MSG_VALUE_PATTERN = Pattern.compile("^(note|warning|error|disabled)$");
|
||||
|
||||
protected final Project project;
|
||||
protected final MixinExtension mixinExtension;
|
||||
protected final Map<SourceSet, T> invokerTasks;
|
||||
private final Collection<Configuration> apConfigurations;
|
||||
|
||||
@@ -64,6 +70,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
Collection<Configuration> apConfigurations,
|
||||
Map<SourceSet, T> invokerTasks) {
|
||||
this.project = project;
|
||||
this.mixinExtension = LoomGradleExtension.get(project).getMixin();
|
||||
this.apConfigurations = apConfigurations;
|
||||
this.invokerTasks = invokerTasks;
|
||||
}
|
||||
@@ -93,6 +100,17 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
put(Constants.MixinArguments.QUIET, "true");
|
||||
}};
|
||||
|
||||
if (mixinExtension.getShowMessageTypes().get()) {
|
||||
args.put(Constants.MixinArguments.SHOW_MESSAGE_TYPES, "true");
|
||||
}
|
||||
|
||||
mixinExtension.getMessages().get().forEach((key, value) -> {
|
||||
checkPattern(key, MSG_KEY_PATTERN);
|
||||
checkPattern(value, MSG_VALUE_PATTERN);
|
||||
|
||||
args.put("AMSG_" + key, value);
|
||||
});
|
||||
|
||||
project.getLogger().debug("Outputting refmap to dir: " + getRefmapDestinationDir(task) + " for compile task: " + task);
|
||||
args.forEach((k, v) -> passArgument(task, k, v));
|
||||
} catch (IOException e) {
|
||||
@@ -124,4 +142,12 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
passMixinArguments(entry.getValue(), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkPattern(String input, Pattern pattern) {
|
||||
final Matcher matcher = pattern.matcher(input);
|
||||
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("Mixin argument (%s) does not match pattern (%s)".formatted(input, pattern.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.gradle.api.Action;
|
||||
import org.gradle.api.InvalidUserDataException;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.provider.MapProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
@@ -42,6 +43,8 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
protected final Project project;
|
||||
protected final Property<Boolean> useMixinAp;
|
||||
private final Property<String> refmapTargetNamespace;
|
||||
private final MapProperty<String, String> messages;
|
||||
private final Property<Boolean> showMessageTypes;
|
||||
|
||||
public MixinExtensionApiImpl(Project project) {
|
||||
this.project = Objects.requireNonNull(project);
|
||||
@@ -51,6 +54,12 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
this.refmapTargetNamespace = project.getObjects().property(String.class)
|
||||
.convention(MappingsNamespace.INTERMEDIARY.toString());
|
||||
this.refmapTargetNamespace.finalizeValueOnRead();
|
||||
|
||||
this.messages = project.getObjects().mapProperty(String.class, String.class);
|
||||
this.messages.finalizeValueOnRead();
|
||||
|
||||
this.showMessageTypes = project.getObjects().property(Boolean.class);
|
||||
this.showMessageTypes.convention(false).finalizeValueOnRead();
|
||||
}
|
||||
|
||||
protected final PatternSet add0(SourceSet sourceSet, String refmapName) {
|
||||
@@ -121,6 +130,21 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
add(sourceSetName, x -> { });
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapProperty<String, String> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<Boolean> getShowMessageTypes() {
|
||||
return showMessageTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messages(Action<MapProperty<String, String>> action) {
|
||||
action.execute(messages);
|
||||
}
|
||||
|
||||
private SourceSet resolveSourceSet(String sourceSetName) {
|
||||
// try to find sourceSet with name sourceSetName in this project
|
||||
SourceSet sourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().findByName(sourceSetName);
|
||||
|
||||
@@ -111,6 +111,7 @@ public class Constants {
|
||||
public static final String OUT_REFMAP_FILE = "outRefMapFile";
|
||||
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
|
||||
public static final String QUIET = "quiet";
|
||||
public static final String SHOW_MESSAGE_TYPES = "showMessageTypes";
|
||||
|
||||
private MixinArguments() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user