Class MetaInfService

java.lang.Object
aQute.bnd.osgi.metainf.MetaInfService

public class MetaInfService extends Object
Holds our knowledge about the META-INF/services/ files.

These are files that are used by Java in the Service Loader. Normally they have the name of a service type and are filled with their implementations, one per line.

We allow these lines to be annotated like Java types. Annotations are in the comments to not disturb other users of these files. They look like:

#import aQute.bnd.annotation.spi.ServiceProvider
  • Constructor Details

    • MetaInfService

      public MetaInfService(String serviceName, Resource resource) throws Exception
      Create a MetaInfService from a resource
      Parameters:
      serviceName - the fqn for the service interface
      resource - the resource
      Throws:
      Exception
    • MetaInfService

      public MetaInfService(String serviceName, InputStream in) throws IOException
      Create a MetaInfService from an input stream
      Parameters:
      serviceName - the fqn for the service interface
      in - the input stream
      Throws:
      IOException
    • MetaInfService

      public MetaInfService(String serviceName, Reader in) throws IOException
      Create a MetaInfService from a reader
      Parameters:
      serviceName - the fqn for the service interface
      in - the reader
      Throws:
      IOException
    • MetaInfService

      public MetaInfService(String serviceName)
      Create an empty
      Parameters:
      serviceName - the fqn for the service interface
    • MetaInfService

      public MetaInfService(String serviceName, String source)
      Create from a source. The source should be the content as defined for files in the META-INF/services directory. This may include imports and annotations in the comments.
      Parameters:
      serviceName - the fqn for the service interface
      source - the source code
  • Method Details

    • getServiceFiles

      public static Map<String, MetaInfService> getServiceFiles(Jar jar) throws Exception
      get the META-INF service files from a JAR
      Parameters:
      jar - the jar
      Throws:
      Exception
    • add

      public boolean add(String serviceImpl, Parameters annotations, String... comments)
      Add an extra implementation to the service files.
      Parameters:
      serviceImpl - the implementation fqn
      annotations - the annotations for this implementation
      comments - the comments that come before the definition
    • getImplementations

      public Map<String, MetaInfService.Implementation> getImplementations()
      Get the current list of implementations
    • isDirty

      public boolean isDirty()
      Return if changes were made after the constructor parsing the source.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • append

      public void append(StringBuilder sb)