Class MetadataLoader
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant for theAirlineModuleannotation classstatic final StringConstant for thecom.google.inject.Injectannotation classprivate static Map<String, Class<? extends Annotation>> static final StringConstant for thejakarta.inject.Injectannotation classstatic final StringConstant for thejavax.inject.Injectannotation class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidbuildGroupsHierarchy(List<CommandGroupMetadata> commandGroups, Map<String, CommandGroupMetadata> subGroups) private static voidcheckForInjectionAnnotation(MetadataLoader.InjectionMetadata injectionMetadata, Field field, List<Field> path, String annotationClass, ParserMetadata<?> parserConfig) private static voidcollectPartial(Map<Class<? extends Annotation>, Set<Integer>> partials, Partial partial) private static voidcreateGroupsFromAnnotations(List<CommandMetadata> allCommands, List<CommandMetadata> newCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) static CommandMetadataloadCommand(Class<?> commandType, ParserMetadata<?> parserConfig) Loads command meta-datastatic CommandMetadataloadCommand(Class<?> commandType, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-datastatic CommandGroupMetadataloadCommandGroup(String name, String description, boolean hidden, Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand, Iterable<CommandMetadata> commands) Loads command group meta-datastatic <T> List<CommandMetadata> loadCommands(Iterable<Class<? extends T>> defaultCommands, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-datastatic voidloadCommandsIntoGroupsByAnnotation(List<CommandMetadata> allCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass) static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass, ParserMetadata<C> parserConfigOverride) Loads the metadata for a CLIstatic <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, Iterable<HelpSection> baseHelpSections, ParserMetadata<C> parserConfig) Loads global meta-dataprotected static Map<String, HelpSection> loadHelpSections(Class<?> sourceClass, Map<String, HelpSection> baseHelpSections) static voidloadInjectionMetadata(Class<?> type, MetadataLoader.InjectionMetadata injectionMetadata, List<Field> fields, ParserMetadata<?> parserConfig) Loads injection meta-dataloadInjectionMetadata(Class<?> type, ParserMetadata<?> parserConfig) Loads injection meta-dataprivate static <C> ParserMetadata<C> loadParser(Parser parserConfig) static <C> ParserMetadata<C> loadParser(Class<?> cliClass) private static Map<Class<? extends Annotation>, Set<Integer>> loadPartials(Field field) static SuggesterMetadataloadSuggester(Class<? extends Suggester> suggesterClass, ParserMetadata<?> parserConfig) Loads suggester meta-dataprivate static List<OptionMetadata> mergeOptionSet(List<OptionMetadata> options) private static List<OptionMetadata> overrideOptionSet(List<OptionMetadata> options) private static voidtryOverrideOptions(Map<Set<String>, OptionMetadata> optionIndex, Set<String> names, OptionMetadata parent)
-
Field Details
-
AIRLINE_MODULE
-
JAVAX_INJECT_INJECT
Constant for thejavax.inject.Injectannotation class- See Also:
-
JAKARTA_INJECT_INJECT
Constant for thejakarta.inject.Injectannotation class- See Also:
-
COM_GOOGLE_INJECT_INJECT
Constant for thecom.google.inject.Injectannotation class- See Also:
-
dynamicAnnotationCache
-
-
Constructor Details
-
MetadataLoader
public MetadataLoader()
-
-
Method Details
-
loadParser
-
loadParser
-
loadGlobal
-
loadGlobal
public static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass, ParserMetadata<C> parserConfigOverride) Loads the metadata for a CLI- Parameters:
cliClass- Class that has theCliannotationparserConfigOverride- Optional parser configuration, note that theCli.parserConfiguration()field is normally used to provide a parser configuration via annotation but in some situations this may not be possible, e.g. constructing user alias search paths programmatically, in which case providing a parser configuration here overrides anything specified directly on the annotation- Returns:
- Global metadata
-
loadGlobal
public static <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, Iterable<HelpSection> baseHelpSections, ParserMetadata<C> parserConfig) Loads global meta-data- Parameters:
name- CLI namedescription- CLI descriptiondefaultCommand- Default CommanddefaultGroupCommands- Default Group Commandsgroups- Command Groupsrestrictions- RestrictionsbaseHelpSections- Base help sectionsparserConfig- Parser Configuration- Returns:
- Global meta-data
-
loadCommandGroup
public static CommandGroupMetadata loadCommandGroup(String name, String description, boolean hidden, Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand, Iterable<CommandMetadata> commands) Loads command group meta-data- Parameters:
name- Group namedescription- Group descriptionhidden- Whether the group is hiddendefaultCommand- Default command for the groupcommands- Commands for the group- Returns:
- Command group meta-data
-
loadCommands
public static <T> List<CommandMetadata> loadCommands(Iterable<Class<? extends T>> defaultCommands, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-data- Parameters:
defaultCommands- Default command classes- Returns:
- Command meta-data
-
loadCommand
Loads command meta-data- Parameters:
commandType- Command class- Returns:
- Command meta-data
-
loadCommand
public static CommandMetadata loadCommand(Class<?> commandType, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-data- Parameters:
commandType- Command TypebaseHelpSections- Base set of help sections- Returns:
- Command meta-data
-
loadHelpSections
protected static Map<String, HelpSection> loadHelpSections(Class<?> sourceClass, Map<String, HelpSection> baseHelpSections) -
loadSuggester
public static SuggesterMetadata loadSuggester(Class<? extends Suggester> suggesterClass, ParserMetadata<?> parserConfig) Loads suggester meta-data- Parameters:
suggesterClass- Suggester class- Returns:
- Suggester meta-data
-
loadInjectionMetadata
public static MetadataLoader.InjectionMetadata loadInjectionMetadata(Class<?> type, ParserMetadata<?> parserConfig) Loads injection meta-dataGiven a class that represents a command, searches its fields to find those that are annotated with Airline annotations e.g.
Option,Argumentsin order to discover all the options and arguments for a command. This also includes walking back up the superclass hierarchy so options and arguments may be defined in shared base classes and still discovered.Additionally options and arguments may be modularised out into separate classes that can be composed into your command classes by defining a field of the appropriate type and annotating it with an injection annotation to tell Airline it also needs to discover options inside that class.
Historically Airline supported only the
javax.inject.Injectannotation, but with the move of mostjavaxpackages (Java EE) to the stewardship of the Eclipse Foundation those packages are gradually being migrated into thejakartanamespace. As of 2.9.0 Airline makes the choice of annotation fully configurable via the parser configuration. To avoid potential class loading issues these are specified as string class names with the metadata loader dynamically loading the relevant annotation classes if they are present on the runtime classpath. As of 3.10.0 we only look for our ownAirlineModuleannotation and any other composition annotation e.g.jakarta.inject.InjectMUST be explicitly configured.- Parameters:
type- ClassparserConfig- Parser Configuration- Returns:
- Injection meta-data
-
loadInjectionMetadata
public static void loadInjectionMetadata(Class<?> type, MetadataLoader.InjectionMetadata injectionMetadata, List<Field> fields, ParserMetadata<?> parserConfig) Loads injection meta-data- Parameters:
type- ClassinjectionMetadata- Injection meta-datafields- Fields
-
checkForInjectionAnnotation
private static void checkForInjectionAnnotation(MetadataLoader.InjectionMetadata injectionMetadata, Field field, List<Field> path, String annotationClass, ParserMetadata<?> parserConfig) -
loadPartials
-
collectPartial
-
mergeOptionSet
-
overrideOptionSet
-
tryOverrideOptions
private static void tryOverrideOptions(Map<Set<String>, OptionMetadata> optionIndex, Set<String> names, OptionMetadata parent) -
loadCommandsIntoGroupsByAnnotation
public static void loadCommandsIntoGroupsByAnnotation(List<CommandMetadata> allCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) -
createGroupsFromAnnotations
private static void createGroupsFromAnnotations(List<CommandMetadata> allCommands, List<CommandMetadata> newCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) -
buildGroupsHierarchy
protected static void buildGroupsHierarchy(List<CommandGroupMetadata> commandGroups, Map<String, CommandGroupMetadata> subGroups)
-