feat: option to skip service provider generation

This commit is contained in:
zaaarf 2023-05-26 17:56:33 +02:00
parent d3ebad7260
commit a90af3bb4b
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 28 additions and 3 deletions

View file

@ -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<String> 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;

View file

@ -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<String> 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);
}
/**