From a90af3bb4b156ea937a2e3507e9f0e15f70c882b Mon Sep 17 00:00:00 2001 From: zaaarf Date: Fri, 26 May 2023 17:56:33 +0200 Subject: feat: option to skip service provider generation --- src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 14 +++++++++++--- .../ftbsc/lll/processor/tools/ProcessorOptions.java | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/main/java/ftbsc/lll/processor') diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index 1b710b0..0f6935a 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -36,9 +36,8 @@ import static ftbsc.lll.processor.tools.JavaPoetUtils.*; * The actual annotation processor behind the magic. * It (implicitly) implements the {@link Processor} interface by extending {@link AbstractProcessor}. */ -@SupportedAnnotationTypes({"ftbsc.lll.processor.annotations.Patch", "ftbsc.lll.processor.annotations.RegisterBareInjector"}) +@SupportedAnnotationTypes({"ftbsc.lll.processor.annotations.Patch", "ftbsc.lll.processor.annotations.BareInjector"}) @SupportedSourceVersion(SourceVersion.RELEASE_8) -@SupportedOptions({"mappingsFile", "anonymousClassWarning", "obfuscateInjectorMetadata"}) public class LilleroProcessor extends AbstractProcessor { /** * A {@link Set} of {@link String}s that will contain the fully qualified names @@ -51,6 +50,15 @@ public class LilleroProcessor extends AbstractProcessor { */ public final ProcessorOptions options = new ProcessorOptions(processingEnv); + /** + * Method overriding default implementation to manually pass supported options. + * @return a {@link Set} of options supported by this processor. + */ + @Override + public Set getSupportedOptions() { + return ProcessorOptions.SUPPORTED; + } + /** * Where the actual processing happens. * It filters through whatever annotated class it's fed, and checks whether it contains @@ -82,7 +90,7 @@ public class LilleroProcessor extends AbstractProcessor { } } } - if (!this.injectors.isEmpty()) { + if (!this.options.noServiceProvider && !this.injectors.isEmpty()) { generateServiceProvider(); return true; } else return false; diff --git a/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java b/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java index 9bbdd10..0ef8a18 100644 --- a/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java +++ b/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java @@ -9,12 +9,24 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; /** * Class in charge of containing, parsing and processing all processor options, * from the simpler booleans to the more complicated mapper. */ public class ProcessorOptions { + + /** + * A {@link Set} of options currently supported by the processor. + */ + public static final Set SUPPORTED = new HashSet<>(Arrays.asList( + "mappingsFile", "anonymousClassWarning", "obfuscateInjectorMetadata", + "noServiceProvider" + )); + /** * The environment the processor is acting in. */ @@ -38,6 +50,10 @@ public class ProcessorOptions { */ public final boolean obfuscateInjectorMetadata; + /** + * Whether the processor should skip the generation of the service provider. + */ + public final boolean noServiceProvider; /** * The public constructor, parses and stores all given arguments. @@ -71,6 +87,7 @@ public class ProcessorOptions { } this.anonymousClassWarning = parseBooleanArg(env.getOptions().get("anonymousClassWarning"), true); this.obfuscateInjectorMetadata = parseBooleanArg(env.getOptions().get("obfuscateInjectorMetadata"), true); + this.noServiceProvider = parseBooleanArg(env.getOptions().get("noServiceProvider"), false); } /** -- cgit v1.2.3-56-ga3b1