Class DescriptorFormat

java.lang.Object
io.gdcc.spi.meta.descriptor.DescriptorFormat

public final class DescriptorFormat extends Object
Defines constants for the format and structure of plugin plugin files. These descriptors provide metadata about plugins, including their implementation class, type, contracts, and required providers.
    - DESCRIPTOR_DIRECTORY: Specifies the directory where plugin plugin files are located. - PLUGIN_CLASS_FIELD: Defines the key used to identify the plugin's implementation class. - PLUGIN_KIND_FIELD: Defines the key used to specify the base contract type of the plugin. - CONTRACT_PREFIX and CONTRACT_SUFFIX: Define the keys used to denote the contracts implemented by the plugin and their associated API levels. - REQUIRED_PROVIDER_PREFIX and REQUIRED_PROVIDER_SUFFIX: Define the keys used to represent required providers and their associated API levels.
  • Field Details

  • Method Details

    • transformClassName

      public static String transformClassName(Class<?> klass)
      Transforms the provided class into its canonical name representation. Reusable in different places to keep serialization from class to FQCN aligned.
      Parameters:
      klass - the Class object whose canonical name is to be returned
      Returns:
      the name of the specified class, or null if the class does not have a name. Note: not using the canonical name to avoid issues with inner classes and de/serialization.
    • toFilename

      public static String toFilename(Class<?> klass)
    • toFilename

      public static String toFilename(String fqcn)
    • toPath

      public static String toPath(Class<?> klass)
    • toPath

      public static String toPath(String fqcn)
    • toContractLevel

      public static String toContractLevel(Class<?> contractClass)
    • toContractLevel

      public static String toContractLevel(String contractFQCN)
    • toRequiredProviderLevel

      public static String toRequiredProviderLevel(Class<?> providerClass)
    • toRequiredProviderLevel

      public static String toRequiredProviderLevel(String providerFQCN)
    • write

      public static void write(Descriptor descriptor, Writer writer) throws IOException
      Serializes the provided Descriptor into the given Writer in the form of a properties file, encoding plugin metadata such as plugin class, plugin kind, implemented contracts, and required providers.
      Parameters:
      descriptor - the Descriptor containing the plugin metadata to be serialized
      writer - the Writer where the plugin properties will be written
      Throws:
      IOException - if an I/O error occurs while writing to the Writer
    • read

      public static Descriptor read(Reader reader) throws IOException
      Reads a plugin plugin from the serialized properties format.

      The returned plugin contains the mandatory plugin class and base contract fields, plus all parsed contract/provider API levels found in the input.

      Parameters:
      reader - the character stream containing plugin properties
      Returns:
      the parsed plugin.
      Throws:
      IOException - if the properties cannot be read
      IllegalArgumentException - if mandatory fields are missing or if any level value cannot be parsed as an integer
    • read

      public static Descriptor read(String content)
      Reads a plugin plugin from the given string content. This method parses the input string into a Descriptor object. It internally utilizes a StringReader to read the string and expects the content to be in a properties-based serialized format.
      Parameters:
      content - the string content containing serialized plugin properties
      Returns:
      the parsed Descriptor
      Throws:
      RuntimeException - if an I/O error occurs
      IllegalArgumentException - if mandatory fields are missing