Class ManifestFileVar


public class ManifestFileVar extends DefaultingVar
Manifest file entries variable resolver.

The format for this var is "$MF{key[,default]}".

This variable resolver requires that a ManifestFile object be made available by either:

  • Classpath/default manifest discovery when using the no-arg constructor.
  • Constructing the var via create(Supplier) (per-instance).
Example:

// Create a ManifestFile object that contains the manifest of the jar file containing this class. ManifestFile manifestFile = new ManifestFile(this.getClass()); // Create a variable resolver that resolves manifest file entries (e.g. "$MF{Main-Class}") VarResolver varResolver = VarResolver.create().vars(ManifestFileVar.create(() -> manifestFile)).build(); // Use it! System.out.println(varResolver.resolve("The main class is $MF{Main-Class}"));

Since this is a SimpleVar, any variables contained in the result will be recursively resolved. Likewise, if the arguments contain any variables, those will be resolved before they are passed to this var.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • create

      public static ManifestFileVar create(Supplier<ManifestFile> supplier)
      Creates a ManifestFileVar bound to a per-instance Supplier of ManifestFile.

      The supplier is invoked on every resolve.

      Parameters:
      supplier - The supplier of ManifestFile for this var instance. Must not be null.
      Returns:
      A new ManifestFileVar instance backed by the supplier.
    • resolve

      public String resolve(VarResolverSession session, String key)
      Description copied from class: Var
      The interface that needs to be implemented for subclasses of SimpleVar.
      Specified by:
      resolve in class Var
      Parameters:
      session - The session object used for a single instance of a var resolution.
      key - The inside argument of the variable.
      Returns:
      The resolved value.
    • isStable

      protected boolean isStable()
      Manifest entries are immutable for the lifetime of the classpath. This var opts in to compile-time stable-value folding.
      Overrides:
      isStable in class Var
      Returns:
      Always true.